Created
August 16, 2018 12:41
-
-
Save 73nko/c2fe1e0072f8fc48c6d45c591bed508b to your computer and use it in GitHub Desktop.
A method fro array chunk
This file contains 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, 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