Last active
June 9, 2021 06:37
-
-
Save hmmhmmhm/061802d4588ed37087052c82e57f2b41 to your computer and use it in GitHub Desktop.
Typescript (Javascript) Array Chunk Generator
This file contains 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 chunk = <T>(array: T[], chunkSize: number) => { | |
const result: T[][] = [] | |
for (let i = 0; i < array.length; i += chunkSize) | |
result.push(array.slice(i, i + chunkSize)) | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment