mirror of
https://github.com/motajs/template.git
synced 2026-11-18 10:14:30 +08:00
13 lines
330 B
TypeScript
13 lines
330 B
TypeScript
export const splitArray = <T>(array: T[], predictor: (val: T) => boolean) => {
|
|
const chunks: T[][] = [[]];
|
|
for (const item of array) {
|
|
if (predictor(item)) {
|
|
chunks.push([item]);
|
|
chunks.push([]);
|
|
} else {
|
|
chunks.at(-1)!.push(item);
|
|
}
|
|
}
|
|
return chunks;
|
|
};
|