Skip to content

Instantly share code, notes, and snippets.

@jade-itworkswhy
Created February 1, 2024 12: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 jade-itworkswhy/a0afc632edf1841c6aef4eddac4dd001 to your computer and use it in GitHub Desktop.
Save jade-itworkswhy/a0afc632edf1841c6aef4eddac4dd001 to your computer and use it in GitHub Desktop.
array_helpers.ts
/**
* Splits an array into chunks of a specified size.
* @param array The array to be chunked.
* @param size The size of each chunk.
* @returns An array of chunks.
*/
export const typedChunkByIndex = <T>(array: T[], size: number): T[][] => {
const chunked: T[][] = []
let index = 0
while (index < array.length) {
chunked.push(array.slice(index, index + size))
index += size
}
return chunked
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment