title: How do I check if a string is entirely made of the same substring?
body: <p>I have to create a function which takes a string, and it should return <code>true</code> or <code>false</code> based on whether the input consists of a repeated character sequence. The length of the given string is always greater than <code>1</code> and the character sequence must have at least one repetition.</p>
  
  <pre><code>"aa" // true(entirely contains two strings "a")
  "aaa" //true(entirely contains three string "a")
  "abcabcabc" //true(entirely containas three strings "abc")
  
  "aba" //false(At least there should be two same substrings and nothing more)
  "ababa" //false("ab" exists twice but "a" is extra so false)
  </code></pre>
  
  <p>I have created the below function:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function check(str){
    if(!(str.length &amp;&amp; str.length - 1)) return false;
    let temp = '';
    for(let i = 0;i&lt;=str.length/2;i++){
      temp += str[i]
      //console.log(str.replace(new RegExp(temp,"g"),''))
      if(!str.replace(new RegExp(temp,"g"),'')) return true;
    }
    return false;
  }
  
  console.log(check('aa')) //true
  console.log(check('aaa')) //true
  console.log(check('abcabcabc')) //true
  console.log(check('aba')) //false
  console.log(check('ababa')) //false</code></pre>
  </div>
  </div>
  </p>
  
  <p>Checking of this is part of the real problem. I can't afford a non-efficient solution like this. First of all, it's looping through half of the string.</p>
  
  <p>The second problem is that it is using <code>replace()</code> in each loop which makes it slow. Is there a better solution regarding performance?</p>