2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
19
Task/Permutations/JavaScript/permutations-6.js
Normal file
19
Task/Permutations/JavaScript/permutations-6.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
(function (lst) {
|
||||
'use strict';
|
||||
|
||||
const permutations = (xs) => xs.length ? (
|
||||
flatMap((x) => flatMap((xs) => [[x].concat(xs)],
|
||||
permutations(del(x, xs))), xs)
|
||||
) : [[]],
|
||||
|
||||
flatMap = (f, xs) => [].concat.apply([], xs.map(f)),
|
||||
|
||||
del = (x, xs) => xs.length ? x === xs[0] ? (
|
||||
xs.slice(1)
|
||||
) : [xs[0]].concat(del(x, xs.slice(1))
|
||||
) : [];
|
||||
|
||||
|
||||
return permutations(lst);
|
||||
|
||||
})(["Aardvarks", "eat", "ants"]);
|
||||
Loading…
Add table
Add a link
Reference in a new issue