permutations.js 514 B

123456789101112131415161718
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.permutations = void 0;
  4. function* permutations(arr, m = []) {
  5. if (arr.length === 0) {
  6. // @ts-ignore:
  7. yield m;
  8. }
  9. else {
  10. for (let i = 0; i < arr.length; i++) {
  11. let curr = arr.slice();
  12. let next = curr.splice(i, 1);
  13. yield* permutations(curr.slice(), m.concat(next));
  14. }
  15. }
  16. }
  17. exports.permutations = permutations;
  18. //# sourceMappingURL=permutations.js.map