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.
23 lines
608 B
23 lines
608 B
4 weeks ago
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.splitWhen = exports.flatten = void 0;
|
||
|
function flatten(items) {
|
||
|
return items.reduce((collection, item) => [].concat(collection, item), []);
|
||
|
}
|
||
|
exports.flatten = flatten;
|
||
|
function splitWhen(items, predicate) {
|
||
|
const result = [[]];
|
||
|
let groupIndex = 0;
|
||
|
for (const item of items) {
|
||
|
if (predicate(item)) {
|
||
|
groupIndex++;
|
||
|
result[groupIndex] = [];
|
||
|
}
|
||
|
else {
|
||
|
result[groupIndex].push(item);
|
||
|
}
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
|
exports.splitWhen = splitWhen;
|