It will iterate through each element of the provided values array and add the result of invoking iteratee function/property for each element to produce the desired sum.
values
iteratee
sum
The array to iterate over.
The function/property to get the value per element.
The sum value.
1.0.0
sumByFn([1, 2, 3], number => number); // => 6 Copy
sumByFn([1, 2, 3], number => number); // => 6
sumByFn([{ a: 1 }, { a: 2 }, { a: 3 }], ({ a }) => a); // => 6 Copy
sumByFn([{ a: 1 }, { a: 2 }, { a: 3 }], ({ a }) => a); // => 6
sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], "a"); // => 6 Copy
sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], "a"); // => 6
It will iterate through each element of the provided
values
array and add the result of invokingiteratee
function/property for each element to produce the desiredsum
.