Skip to content

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 ParameterDefault typeDescription
TValuenumberThe element type of the array.

Parameters ​

ParameterTypeDescription
valuesTValue[]The values to sum.
iteratee?(value) => numberMaps each value to the number it contributes.

Returns ​

number

The sum, or 0 for an empty array.