Last active
February 19, 2018 10:49
-
-
Save dragonza/a45615fd33c5d1d35be198f95e6b916f to your computer and use it in GitHub Desktop.
Chunk 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
| function chunk(array, size) { | |
| const chunked_arr = []; | |
| let copied = [...array]; // ES6 destructuring | |
| const numOfChild = Math.ceil(copied.length / size); // Round up to the nearest integer | |
| for (let i = 0; i < numOfChild; i++) { | |
| chunked_arr.push(copied.splice(0, size)); | |
| } | |
| return chunked_arr; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment