@beenotung/tslib
Version:
utils library in Typescript
12 lines (11 loc) • 357 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.n_permutation = n_permutation;
/** @description permutation: order matters */
function n_permutation(n, xs) {
if (n == 0)
return [];
if (n == 1)
return xs.map(x => [x]);
return xs.flatMap(x => n_permutation(n - 1, xs).map(xs => [x, ...xs]));
}