Created
August 8, 2022 18:37
-
-
Save NuroDev/129430f94168bcd7f937a3b377ea7fd9 to your computer and use it in GitHub Desktop.
✂️ Chunkify - Splits a provided array into chunks of arrays
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
/** | |
* 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