Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

array.js 630B

12345678910111213141516171819202122
  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;