Skip to content

Instantly share code, notes, and snippets.

@lupomontero
Created June 20, 2018 03:39
Show Gist options
  • Save lupomontero/c2dcfafbb1733783e238c80f477795bb to your computer and use it in GitHub Desktop.
Save lupomontero/c2dcfafbb1733783e238c80f477795bb to your computer and use it in GitHub Desktop.
Split array into batches
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