Created
April 21, 2018 05:19
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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