function findSubString(text, subString){
    var idx = 0,
        i = 0,
        j = 0,
        len = text.length,
        subLen = subString.length;

    for(; i<len; i++){

        if(text[i] == subString[j])
            j++;
        else
            j = 0;

        if(j == 0)
            idx = i;
        else if (j == subLen)
            return idx;
    }

    return -1;

}

@@ -6,70 +6,94 @@
 ion 
-findSubString(text, subString)%7B%0A    var idx = 0,%0A        i = 0
+createStringPermutation(text) %7B%0A    var arr = text.split(''),%0A        len = arr.length
 ,%0A  
@@ -98,21 +98,26 @@
         
-j = 0
+perms = %5B%5D
 ,%0A      
@@ -122,60 +122,103 @@
     
-len = text.length,%0A        subL
+rest,%0A        picked,%0A        restPerms,%0A        next;%0A%0A    if (l
 en =
- subString.length
+= 0)%0A        return %5Btext%5D
 ;%0A%0A 
@@ -223,17 +223,25 @@
 %0A    for
-(
+ (var i=0
 ; i%3Clen;
@@ -249,19 +249,19 @@
 i++)
+ 
 %7B%0A
-%0A
         
 if(t
@@ -260,179 +260,292 @@
     
-if(text%5Bi%5D == subString%5Bj%5D)%0A            j++;%0A        else%0A            j = 0;%0A%0A        if(j == 0)%0A            idx = i;%0A        else if (j == subLen)%0A            return idx;
+rest = Object.create(arr);%0A        picked = rest.splice(i, 1);%0A%0A        restPerms = createStringPermutation(rest.join(''));%0A%0A        for (var j=0, jLen = restPerms.length; j%3C jLen; j++) %7B%0A            next = picked.concat(restPerms%5Bj%5D);%0A            perms.push(next.join(''));%0A        %7D
 %0A   
@@ -563,11 +563,13 @@
 urn 
--1;%0A
+perms;
 %0A%7D%0A

add substring algorithm