loading...
re: Nothing beats a recursive solution when it comes to elegance IMO. const chunk = (xs, n) => { if (xs.length <= n) return [xs]; return [ ...
 

Here are my 2 cents. It is performant and avoids recursion.

const chunk = (xs, n) => xs.reduce((o, x, i) => {
  o[Math.floor(i/n)].push(x);
  return o;
}, Array(Math.ceil(xs.length/n)).fill([]))
Code of Conduct Report abuse