12 lines
345 B
JavaScript
12 lines
345 B
JavaScript
export const splitEvery = (inputArray, perChunk) => {
|
|
const chunks = inputArray.reduce((resultArray, item, index) => {
|
|
const chunkIndex = Math.floor(index / perChunk)
|
|
if (!resultArray[chunkIndex]) {
|
|
resultArray[chunkIndex] = [];
|
|
}
|
|
resultArray[chunkIndex].push(item);
|
|
return resultArray;
|
|
}, []);
|
|
return chunks;
|
|
};
|