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

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

Added visualizations

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