Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function permAlone(str) {
- var permutationList = function(str) {
- console.log("=== Start ===");
- var arr = str.split("");
- var arrLen = arr.length;
- console.log("arr = " + arr + " at length " + arrLen);
- var permutations = [];
- if(arrLen === 0) {
- console.log("=== End === " + " string returned!");
- return [str];
- }
- for(var i = 0; i < arr.length; i++) {
- var others = Object.create(arr);
- var item = others.splice(i, 1);
- console.log("others = " + others);
- console.log("item = " + item);
- var permutationOthers = permutationList(others.join(""));
- var permutationOthersLen = permutationOthers.length;
- console.log("permutationOthers = " + permutationOthers + " at length " + permutationOthersLen);
- for(var j = 0; j < permutationOthersLen; j++) {
- var next = item.concat(permutationOthers[j]);
- console.log("next = " + next);
- permutations.push(next.join(""));
- console.log("permutations = " + permutations);
- }
- }
- console.log("=== End ===");
- return permutations;
- };
- return permutationList(str).
- filter(function(item) {
- return !item.search(/(.)\1+/);
- }).
- length;
- }
- console.log(permAlone("abcdefa"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement