Created
March 10, 2022 06:47
-
-
Save inneroot/2a29368d9417523bcf165db154268d8b to your computer and use it in GitHub Desktop.
split array to batches with generator
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
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