Permutations: Difference between revisions

m
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) {
 
return inject([x].concat(ys));
}return inject( [x].concat(ys) );
 
})
})})) : [[]]
}
 
9,659

edits