source: node_modules/es-toolkit/dist/array/chunk.mjs

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

Added visualizations

  • Property mode set to 100644
File size: 465 bytes
Line 
1function chunk(arr, size) {
2 if (!Number.isInteger(size) || size <= 0) {
3 throw new Error('Size must be an integer greater than zero.');
4 }
5 const chunkLength = Math.ceil(arr.length / size);
6 const result = Array(chunkLength);
7 for (let index = 0; index < chunkLength; index++) {
8 const start = index * size;
9 const end = start + size;
10 result[index] = arr.slice(start, end);
11 }
12 return result;
13}
14
15export { chunk };
Note: See TracBrowser for help on using the repository browser.