typedash
Version:
modern, type-safe collection of utility functions
18 lines (16 loc) • 509 B
JavaScript
;
// src/functions/sum/sum.ts
function sum(array, mapper) {
if (array == null) {
return 0;
}
const numbers = array.map((value, index, array_) => {
const result = mapper?.(value, index, array_) ?? // if there's no iteratee, we're in the overload of `sum` that only takes an array of numbers
(value ?? 0);
return result;
});
return numbers.reduce((draft, value) => draft + value, 0);
}
exports.sum = sum;
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.cjs.map