sum(zero?)

Returns the sum of all values in this collection.

The zero argument is the initial value to begin accumulating the sum, and defaults to 0. The sum is aggregated with the plus operator, so an empty string is an equally viable zero for a collection of strings.

On collections

Usage

  • sum()
  • sum(zero)

Related

  • average()

    Returns the arithmetic mean of the collection, by computing its sum and the count of values and returning the quotient.

  • reduce(callback, basis)

    Aggregates every value in this collection with the result collected up to that index.