Skip to content

Instantly share code, notes, and snippets.

@hmmhmmhm
Last active June 9, 2021 06:37
Show Gist options
  • Save hmmhmmhm/061802d4588ed37087052c82e57f2b41 to your computer and use it in GitHub Desktop.
Save hmmhmmhm/061802d4588ed37087052c82e57f2b41 to your computer and use it in GitHub Desktop.
Typescript (Javascript) Array Chunk Generator
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