Skip to content

Instantly share code, notes, and snippets.

@0xch4z
Last active August 20, 2018 20:46
Show Gist options
  • Save 0xch4z/92475d4061e937c9d6cc2bf9857ceb39 to your computer and use it in GitHub Desktop.
Save 0xch4z/92475d4061e937c9d6cc2bf9857ceb39 to your computer and use it in GitHub Desktop.
// chunk array reduces the array to a set of chunks of size n
const chunkArray = (a = [], n = 2) =>
a.reduce((acc, el, idx) => {
const chunk = Math.floor(idx / n);
if (!Array.isArray(acc[chunk])) acc[chunk] = [];
acc[chunk].push(el);
return acc;
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment