Skip to content

Instantly share code, notes, and snippets.

@NuroDev
Created August 8, 2022 18:37
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 NuroDev/129430f94168bcd7f937a3b377ea7fd9 to your computer and use it in GitHub Desktop.
Save NuroDev/129430f94168bcd7f937a3b377ea7fd9 to your computer and use it in GitHub Desktop.
✂️ Chunkify - Splits a provided array into chunks of arrays
/**
* Chunkify
*
* @description Splits up an array into chnks of arrays of a specified size
*
* @param {Array} array - The input array that will be chunkified
* @param {number} [chunkSize] - The size of each chunk (**Default**: 10)
*/
export function chunkify<T>(array: Array<T>, chunkSize: number = 10) {
let results = new Array<Array<T>>();
while (array.length) {
results.push(array.splice(0, chunkSize));
}
return results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment