loading...

re: Array Chunking VIEW POST

FULL DISCUSSION
 

This is generally how I do it if I need to partition and I don't have a utility library.

const splitEvery = (arr, n) => arr.reduce((memo, val) => {
  if(memo[memo.length - 1].length === n) memo.push([]);
  memo[memo.length - 1].push(val);
  return memo;
}, [[]]);
Code of Conduct Report abuse