source: node_modules/es-toolkit/dist/compat/array/chunk.d.mts@ a762898

Last change on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.0 KB
Line 
1/**
2 * Splits an array into smaller arrays of a specified length.
3 *
4 * This function takes an input array and divides it into multiple smaller arrays,
5 * each of a specified length. If the input array cannot be evenly divided,
6 * the final sub-array will contain the remaining elements.
7 *
8 * @template T The type of elements in the array.
9 * @param {ArrayLike<T> | null | undefined} arr - The array to be chunked into smaller arrays.
10 * @param {number} size - The size of each smaller array. Must be a positive integer.
11 * @returns {T[][]} A two-dimensional array where each sub-array has a maximum length of `size`.
12 *
13 * @example
14 * // Splits an array of numbers into sub-arrays of length 2
15 * chunk([1, 2, 3, 4, 5], 2);
16 * // Returns: [[1, 2], [3, 4], [5]]
17 *
18 * @example
19 * // Splits an array of strings into sub-arrays of length 3
20 * chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);
21 * // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]
22 */
23declare function chunk<T>(arr: ArrayLike<T> | null | undefined, size?: number): T[][];
24
25export { chunk };
Note: See TracBrowser for help on using the repository browser.