Skip to content

Instantly share code, notes, and snippets.

@wesleybliss
Created April 21, 2018 05:19
Show Gist options
  • Save wesleybliss/5c4d98e0adf2b5a79de1830d2330bda4 to your computer and use it in GitHub Desktop.
Save wesleybliss/5c4d98e0adf2b5a79de1830d2330bda4 to your computer and use it in GitHub Desktop.
Group a flat array in to a multidimensional one, by chunk size (number of elements per sub-array)
const arrayChunk = (array, chunkSize) =>
Array(Math.ceil(array.length / chunkSize))
.fill()
.map((_, index) => index * chunkSize)
.map(it => array.slice(it, it + chunkSize))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment