|
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 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | function 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 |
|
|---|
| 19 | exports.chunk = chunk;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.