Port 2b6b2fcb6ff7f0c066260c0aa3f14f34e4bc3588 to glitch-soc Signed-off-by: Claire <claire.github-309c@sitedethib.com>
16 lines
411 B
TypeScript
16 lines
411 B
TypeScript
/**
|
|
* Splits a long array so that the resulting nested arrays
|
|
* never exceed the `maxLength` provided.
|
|
* Useful when dealing with endpoints that accept a limited number
|
|
* of parameters
|
|
*/
|
|
export function batchArray<T>(array: T[], maxLength: number) {
|
|
const result: T[][] = [];
|
|
|
|
for (let i = 0; i < array.length; i += maxLength) {
|
|
result.push(array.slice(i, i + maxLength));
|
|
}
|
|
|
|
return result;
|
|
}
|