Advertisement
Guest User

Untitled

a guest
Aug 13th, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function permAlone(str) {  
  2.   var permutationList = function(str) {
  3.     console.log("=== Start ===");
  4.     var arr = str.split("");
  5.     var arrLen = arr.length;
  6.     console.log("arr = " + arr + " at length " + arrLen);
  7.     var permutations = [];
  8.  
  9.     if(arrLen === 0) {
  10.       console.log("=== End === " + " string returned!");
  11.       return [str];
  12.     }
  13.  
  14.     for(var i = 0; i < arr.length; i++) {
  15.       var others = Object.create(arr);
  16.       var item = others.splice(i, 1);
  17.       console.log("others = " + others);
  18.       console.log("item = " + item);
  19.       var permutationOthers = permutationList(others.join(""));
  20.       var permutationOthersLen = permutationOthers.length;
  21.       console.log("permutationOthers = " + permutationOthers + " at length " + permutationOthersLen);
  22.       for(var j = 0; j < permutationOthersLen; j++) {
  23.         var next = item.concat(permutationOthers[j]);
  24.         console.log("next = " + next);
  25.         permutations.push(next.join(""));
  26.         console.log("permutations = " + permutations);
  27.       }
  28.     }
  29.     console.log("=== End ===");
  30.     return permutations;
  31.   };
  32.   return permutationList(str).
  33.     filter(function(item) {
  34.     return !item.search(/(.)\1+/);
  35.   }).
  36.   length;
  37. }
  38. console.log(permAlone("abcdefa"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement