loading...

re: Array Chunking VIEW POST

FULL DISCUSSION
 

Or something like:

const chunk = (arr, n) => [...new Array(Math.ceil(arr.length / n))].map((x, i) => arr.slice(i * n, (i + 1) * n ))
 

That's kind of hard to read (mostly because it's all on one loooong line).

 

Or even shorter 🤣

const chunk = ([...arr], n) => [...Array(Math.ceil(arr.length) / n)].map(_ => arr.splice(0, n))

Code of Conduct Report abuse