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

Loading…
Cancel
Save