Skip to content

Instantly share code, notes, and snippets.

@inneroot
Created March 10, 2022 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inneroot/2a29368d9417523bcf165db154268d8b to your computer and use it in GitHub Desktop.
Save inneroot/2a29368d9417523bcf165db154268d8b to your computer and use it in GitHub Desktop.
split array to batches with generator
function* batchGenerator(array, batchSize) {
const arrCopy = [...array];
while(arrCopy.length>0){
yield arrCopy.splice(0, batchSize);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment