Files
sveltesociety.dev/scripts/chunk.js
Lachlan Collins 615adbaea6 fix: Run updateNpm.js and updatePublint.js in chunked pages (#536)
* fix: Run `updateNpm` and `updatePublint` in chunked pages

* Object shorthand
2023-12-21 10:42:31 +11:00

17 lines
411 B
JavaScript

/**
* Divide an array into multiple smaller array
* @template T
* @param {Array<T>} input
* @param {number} size
* @return {Array<Array<T>>}
*/
export function chunk(input, size) {
size = size < 1 ? 10 : size;
const pages = Math.ceil(input.length / size);
const final = [];
for (let index = 0; index < pages; index++) {
final.push(input.slice(index * size, (index + 1) * size));
}
return final;
}