@naverpay/hidash
Version:
improved lodash
18 lines (16 loc) • 823 B
text/typescript
/**
* @description
* 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.
* This function is similar to lodash's `_.chunk`.
* (Original source inspiration for Lodash version: https://unpkg.com/lodash@4.17.21/chunk.js)
*
* @template T - The type of elements in the array.
* @param {T[] | null | undefined} array - The array to process.
* @param {number} [size=1] - The length of each chunk. Defaults to 1.
* If `size` is less than 1, an empty array is returned.
* @returns {T[][]} Returns the new array of chunks, or an empty array if the input
* array is null/undefined or size is invalid.
*/
declare function chunk<T>(array: T[] | null | undefined, size?: number): T[][];
export { chunk, chunk as default };