Last active
February 1, 2018 13:23
-
-
Save Pamblam/cd7c0064e958344a43c463848d556ecd to your computer and use it in GitHub Desktop.
Break an array into chunks of a certain size
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
| /** | |
| * Break an array into chunks of a certain size | |
| * @param {array} array - The array to break up | |
| * @param {integer} chunksSize - The size of each subarray | |
| * @returns {Array} - Array of subarrays | |
| */ | |
| function arrayChunk(array, chunksSize){ | |
| var i, j, chunk = chunksSize, chunks = []; | |
| for (i = 0, j = array.length; i < j; i += chunk) { | |
| chunks.push(array.slice(i, i + chunk)); | |
| } | |
| return chunks; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment