my-idlers/node_modules/collect.js/dist/methods/sum.js
cp6 fd22b0bf58 V2 (Laravel re-make)
V2 (Laravel re-make)
2022-03-06 02:02:12 +11:00

28 lines
702 B
JavaScript
Vendored

'use strict';
var values = require('../helpers/values');
var _require = require('../helpers/is'),
isFunction = _require.isFunction;
module.exports = function sum(key) {
var items = values(this.items);
var total = 0;
if (key === undefined) {
for (var i = 0, length = items.length; i < length; i += 1) {
total += parseFloat(items[i]);
}
} else if (isFunction(key)) {
for (var _i = 0, _length = items.length; _i < _length; _i += 1) {
total += parseFloat(key(items[_i]));
}
} else {
for (var _i2 = 0, _length2 = items.length; _i2 < _length2; _i2 += 1) {
total += parseFloat(items[_i2][key]);
}
}
return parseFloat(total.toPrecision(12));
};