typedash
Version:
modern, type-safe collection of utility functions
16 lines (15 loc) • 499 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);
}
export { sum };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=chunk-2FPI4RIC.js.map