Created
November 2, 2019 16:39
-
-
Save avilde/d050ef690ca3325c0e0fbfd7d45d687d to your computer and use it in GitHub Desktop.
Chunk an array into smaller arrays (Javascript, Typescript)
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
export const chunkArray = <T>(array: Array<T>, size: number) => { | |
const results = []; | |
while (array.length) { | |
results.push(array.splice(0, size)); | |
} | |
return results; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment