source: node_modules/es-toolkit/dist/array/chunk.d.ts

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

Added visualizations

  • Property mode set to 100644
File size: 1.1 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 {T[]} 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 * @throws {Error} Throws an error if `size` is not a positive integer.
13 *
14 * @example
15 * // Splits an array of numbers into sub-arrays of length 2
16 * chunk([1, 2, 3, 4, 5], 2);
17 * // Returns: [[1, 2], [3, 4], [5]]
18 *
19 * @example
20 * // Splits an array of strings into sub-arrays of length 3
21 * chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);
22 * // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]
23 */
24declare function chunk<T>(arr: readonly T[], size: number): T[][];
25
26export { chunk };
Note: See TracBrowser for help on using the repository browser.