mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-15 23:18:39 +09:00
11 lines
417 B
TypeScript
11 lines
417 B
TypeScript
import assert from 'node:assert/strict';
|
|
|
|
export function chunkArray<T>(items: ReadonlyArray<T>, chunkSize: number): Array<Array<T>> {
|
|
assert(Number.isSafeInteger(chunkSize) && chunkSize > 0, 'Chunk size must be a positive safe integer');
|
|
const chunks: Array<Array<T>> = [];
|
|
for (let index = 0; index < items.length; index += chunkSize) {
|
|
chunks.push(items.slice(index, index + chunkSize));
|
|
}
|
|
return chunks;
|
|
}
|