You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
737 B
JavaScript
29 lines
737 B
JavaScript
'use strict';
|
|
|
|
const helpers = module.exports;
|
|
|
|
helpers.mergeBatch = function (batchData, start, stop, sort) {
|
|
function getFirst() {
|
|
let selectedArray = batchData[0];
|
|
for (let i = 1; i < batchData.length; i++) {
|
|
if (batchData[i].length && (
|
|
!selectedArray.length ||
|
|
(sort === 1 && batchData[i][0].score < selectedArray[0].score) ||
|
|
(sort === -1 && batchData[i][0].score > selectedArray[0].score)
|
|
)) {
|
|
selectedArray = batchData[i];
|
|
}
|
|
}
|
|
return selectedArray.length ? selectedArray.shift() : null;
|
|
}
|
|
let item = null;
|
|
const result = [];
|
|
do {
|
|
item = getFirst(batchData);
|
|
if (item) {
|
|
result.push(item);
|
|
}
|
|
} while (item && (result.length < (stop - start + 1) || stop === -1));
|
|
return result;
|
|
};
|