Skip to content

Instantly share code, notes, and snippets.

@suhaotian
Created September 14, 2017 02:31
Show Gist options
  • Save suhaotian/e8c6f001acaa9f273dc60733c67be8c4 to your computer and use it in GitHub Desktop.
Save suhaotian/e8c6f001acaa9f273dc60733c67be8c4 to your computer and use it in GitHub Desktop.
chunk func
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