t-comm
Version:
专业、稳定、纯粹的工具库
42 lines (38 loc) • 902 B
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
function getStrListLength(list) {
return list.reduce(function (acc, item) {
return acc + item.length;
}, 0);
}
function splitLongList(list, threshold, max) {
if (threshold === void 0) {
threshold = 3800;
}
if (max === void 0) {
max = 3;
}
var strLen = getStrListLength(list);
if (strLen <= threshold) {
return [list];
}
var result = [];
var temp = [];
for (var i = 0; i < list.length; i++) {
var item = list[i];
temp.push(item);
var tempLen = getStrListLength(temp);
if (tempLen >= threshold) {
result.push(temp);
temp = [];
if (result.length >= max - 1) {
temp = list.slice(i + 1);
break;
}
}
}
result.push(temp);
return result;
}
exports.getStrListLength = getStrListLength;
exports.splitLongList = splitLongList;