UNPKG

vite-garden

Version:

Vite Garden -- a part of the threed.ai family of JavaScript-friendly food-growing libraries

20 lines (16 loc) 433 B
export function chunkArray(arrayObject, numberOfItemsPerChunk) { let j = -1; const chunkedArrayObject = arrayObject.reduce( (accumulator, arrayItem, index) => { if (index % numberOfItemsPerChunk === 0) { j += 1; accumulator[j] = [arrayItem]; } else { accumulator[j].push(arrayItem); } return accumulator; }, [] ); return chunkedArrayObject; }