permutaciones con repeticion javascript

Solutions on MaxInterview for permutaciones con repeticion javascript by the best coders in the world

showing results for - "permutaciones con repeticion javascript"
Anna
08 May 2017
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}