Pick start point in outer loop and lengths of different strings for a given starting point
for ( i = 0 ; i < n ; i ++ ) { for ( len = 1 ; len <= n - i ; len ++ ) { var find = s . substr ( i , len ) ; v . push ( find ) ; } }