Documentation / @ripl/utilities / numberSum
Function: numberSum() ​
numberSum<
TValue>(values,iteratee?):number
Defined in: packages/utilities/src/number.ts:83
Computes the sum of an array of numbers, or of values mapped through an optional iteratee.
The iteratee wins wherever one is given, so a numeric array is summed through it rather than raw. Anything that does not resolve to a number — a value with no iteratee to map it, or an iteratee returning undefined — contributes 0.
Type Parameters ​
| Type Parameter | Default type | Description |
|---|---|---|
TValue | number | The element type of the array. |
Parameters ​
| Parameter | Type | Description |
|---|---|---|
values | TValue[] | The values to sum. |
iteratee? | (value) => number | Maps each value to the number it contributes. |
Returns ​
number
The sum, or 0 for an empty array.