title: Find all strings of length 1 through N in String of length N
body: <p>I'm trying to find all substrings within an string. That is, all strings of length 1 through N in a string of length N.</p>
  
  <p><strong>Example</strong></p>
  
  <pre><code>N = '1079'
  subStrings = [1,0,7,9,10,07,79,107,079,1079]
  </code></pre>
  
  <p><strong>First Attempt</strong></p>
  
  <p>I have a solution that works on strings of relatively small N but on larger Ns the solution is extremely slow. Here's the current solution:</p>
  
  <pre><code>N = 'somestring'
  l = N.length
  k = 1
  subStrings = []
  
  while (k &lt;= l) {
    i = 0
    while (i + k &lt;= l) {
      subStrings.push(N.slice(i,k+i))
      i++
    } 
    k++
  }
  
  // subStrings is an array containing the substrings
  </code></pre>
  
  <p>How can I improve the performance of the algorithm to return all substrings? </p>