Created
March 18, 2021 20:43
-
-
Save nblackburn/67a2578bc5bb4b49b1948699c1bc4f1e to your computer and use it in GitHub Desktop.
Break up an array into chunks of a given size.
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
module.exports = (data, limit = 10) => { | |
let chunk = -1; | |
let chunks = []; | |
for (let index = 0; index < data.length; index++) { | |
if (index % limit === 0) { | |
chunk += 1; | |
chunks.push([]); | |
} | |
if (data[index]) { | |
chunks[chunk].push(data[index]); | |
} | |
} | |
return chunks; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment