Created
June 20, 2018 03:39
-
-
Save lupomontero/c2dcfafbb1733783e238c80f477795bb to your computer and use it in GitHub Desktop.
Split array into batches
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
const splitArrayIntoBatches = (arr, limit) => arr.reduce((memo, item) => { | |
if (memo.length && memo[memo.length - 1].length < limit) { | |
memo[memo.length - 1].push(item); | |
return memo; | |
} | |
return [...memo, [item]]; | |
}, []); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment