fn
sum
v0.0.3testedReturns the sum of all the elements in an array
Example
ts
sum([1, 2, 3, 4, 5]) // => 15
sum([{ value: 1 }, { value: 2 }, { value: 3 }], (item) => item.value) // => 6Signatures
ts
export function sum<Value extends number>(array: Value[]): number;ts
export function sum<Value>(array: Value[], getValue: (item: Value) => number): number;Type Parameters
ValueParameters
| Parameter | Type | Description |
|---|---|---|
array | Value[] | The array to sum |
getValue? | ((item: Value) => number) | undefined | A function that returns the value to sum from each element in the array |
Returns
numberThe sum of all the elements in the array