Created
September 14, 2017 02:31
-
-
Save suhaotian/e8c6f001acaa9f273dc60733c67be8c4 to your computer and use it in GitHub Desktop.
chunk func
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
function chunk(array, chunkSize) { | |
if (!chunkSize) throw new Error('chunkSize must be greater than 0') | |
return array.reduce((chunked, value, i) => { | |
if (!(i % chunkSize)) chunked.push([]) | |
chunked[chunked.length - 1].push(value) | |
return chunked | |
}, []) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment