I have this routine which will group an array, groups of x/chunkSize items.
const createGroupedArray = function (arr, chunkSize) {
if(!Number.isInteger(chunkSize)){
throw 'Chunk size must be an integer.';
}
if(chunkSize < 1){
throw 'Chunk size must be greater than 0.';
}
const groups = [];
let i = 0;
while (i < arr.length) {
groups.push(arr.slice(i, i += chunkSize));
}
return groups;
};
so if I pass it:
createGroupedArray([1,2,3,4,5],2)
I get:
[ [ 1, 2 ], [ 3, 4 ], [ 5 ] ]
and if I do:
createGroupedArray([1,2,3],1)
I get:
[ [ 1 ], [ 2 ], [ 3 ] ]
Does anyone know how I can test this? I am using it in a db migration script and it can't fail lol.
The reason I am doing this, is because I want to write to the db, but only ~10,000 records at a time.