Permutations: Difference between revisions
m
→Functional (ES5)
Line 2,109:
return [].concat.apply([], xs.map(f));
}
// monadic return/inject for lists
function inject(x) {
return [x];
}
// drops first instance found
function deleted(x, xs) {
Line 2,126:
function permutations(xs) {
return xs.length ? (
chain( xs, function (x) {
return chain( permutations(deleted(x, xs)), function (ys) {
})})) : [[]]
}
|