super-utils-plus
Version:
A superior alternative to Lodash with improved performance, TypeScript support, and developer experience
19 lines (18 loc) • 497 B
TypeScript
/**
* Creates an array of elements split into groups the length of size.
* If array can't be split evenly, the final chunk will be the remaining elements.
*
* @param array - The array to process
* @param size - The length of each chunk
* @returns The new array of chunks
*
* @example
* ```ts
* chunk([1, 2, 3, 4], 2);
* // => [[1, 2], [3, 4]]
*
* chunk([1, 2, 3, 4, 5], 2);
* // => [[1, 2], [3, 4], [5]]
* ```
*/
export declare function chunk<T>(array: T[], size?: number): T[][];