Created
February 1, 2024 12:47
-
-
Save jade-itworkswhy/a0afc632edf1841c6aef4eddac4dd001 to your computer and use it in GitHub Desktop.
array_helpers.ts
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
/** | |
* 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