Math.sum()

Get the sum of an Array or Set of numbers.

Signatures

To sum an Array of Numbers:

Math.sum(numbers: Array<Number>) => Number

To sum a Set of Numbers:

Math.sum(numbers: Set<Number>) => Number

Description

Get the sum of an Array or Set of Numbers.

Parameters

Parameter Type Required Description

numbers

Array or Set of Numbers

Yes

Numbers to sum.

Return value

Type Description

Number

Sum of the provided numbers.

Examples

Sum an Array of numbers

Math.sum([1, 2, 3])
6

Sum a Set of numbers

// `toSet()` converts the Array of numbers to a Set.
let set = [1, 2, 3].toSet()
Math.sum(set)
6

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!