You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
630 B

2 years ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.splitWhen = exports.flatten = void 0;
  4. function flatten(items) {
  5. return items.reduce((collection, item) => [].concat(collection, item), []);
  6. }
  7. exports.flatten = flatten;
  8. function splitWhen(items, predicate) {
  9. const result = [[]];
  10. let groupIndex = 0;
  11. for (const item of items) {
  12. if (predicate(item)) {
  13. groupIndex++;
  14. result[groupIndex] = [];
  15. }
  16. else {
  17. result[groupIndex].push(item);
  18. }
  19. }
  20. return result;
  21. }
  22. exports.splitWhen = splitWhen;