Implemented suggesting improvements
This commit is contained in:
14
test/permutations/permutations.js
Normal file
14
test/permutations/permutations.js
Normal file
@ -0,0 +1,14 @@
|
||||
const permutations = arr => {
|
||||
if (arr.length <= 2) return arr.length === 2 ? [arr, [arr[1], arr[0]]] : arr;
|
||||
return arr.reduce(
|
||||
(acc, item, i) =>
|
||||
acc.concat(
|
||||
permutations([...arr.slice(0, i), ...arr.slice(i + 1)]).map(val => [
|
||||
item,
|
||||
...val,
|
||||
])
|
||||
),
|
||||
[]
|
||||
);
|
||||
};
|
||||
module.exports = permutations;
|
||||
Reference in New Issue
Block a user