Skip to content

Instantly share code, notes, and snippets.

@73nko
Created August 16, 2018 12:41
Show Gist options
  • Save 73nko/c2fe1e0072f8fc48c6d45c591bed508b to your computer and use it in GitHub Desktop.
Save 73nko/c2fe1e0072f8fc48c6d45c591bed508b to your computer and use it in GitHub Desktop.
A method fro array chunk
function chunk(array, size) {
//declaring variable 'chunked' as an empty array
let chunked = []
//looping through the array until it has been entirely "manipulated" or split into our subarrays
while(array.length > 0) {
//taking the spliced segments completely out of our original array
//pushing these subarrays into our new "chunked" array
chunked.push(array.splice(0, size))
}
//returning the new array of subarrays
return chunked
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment