1function permutator (input) {
2 var set =[];
3 function permute (arr, data) {
4 var cur, memo = data || [];
5
6 for (var i = 0; i < arr.length; i++) {
7 cur = arr.splice(i, 1)[0];
8 if (arr.length === 0) set.push(memo.concat([cur]));
9 permute(arr.slice(), memo.concat([cur]));
10 arr.splice(i, 0, cur);
11 }
12 return set;
13 }
14 return permute(input);
15}