getBundles -> getBatches

master
mjkhan21 5 months ago
parent f480e881ca
commit b0e9421834

@ -126,7 +126,7 @@ var download = {
}
};
function getBundles(array, keymapper, size = 50) {
function getBatches(array, keymapper, size = 50) {
let byKey = array.reduce((result, item) => {
let key = keymapper(item),
items = result[key];
@ -135,18 +135,18 @@ function getBundles(array, keymapper, size = 50) {
items.push(item);
return result;
}, {}),
bundle = [],
bundles = [];
batch = [],
batchs = [];
for (let items of Object.values(byKey)) {
bundle = bundle.concat(items);
if (bundle.length < size) continue;
batch = batch.concat(items);
if (batch.length < size) continue;
bundles.push([].concat(bundle));
bundle.splice(0);
batchs.push([].concat(batch));
batch.splice(0);
}
if (bundle.length > 0)
bundles.push(bundle);
return bundles;
if (batch.length > 0)
batchs.push(batch);
return batchs;
}
function upload(options) {

Loading…
Cancel
Save