26 lines
616 B
JavaScript
26 lines
616 B
JavaScript
import { iteratee } from '../util/iteratee.mjs';
|
|
|
|
function sumBy(array, iteratee$1) {
|
|
if (!array || !array.length) {
|
|
return 0;
|
|
}
|
|
if (iteratee$1 != null) {
|
|
iteratee$1 = iteratee(iteratee$1);
|
|
}
|
|
let result = undefined;
|
|
for (let i = 0; i < array.length; i++) {
|
|
const current = iteratee$1 ? iteratee$1(array[i]) : array[i];
|
|
if (current !== undefined) {
|
|
if (result === undefined) {
|
|
result = current;
|
|
}
|
|
else {
|
|
result += current;
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
export { sumBy };
|