Last change
on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
608 bytes
|
Rev | Line | |
---|
[6a3a178] | 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;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.