reduce / sum
Reduces the array to a single value.
Syntax
arr.reduce(0) { |t, e| t + e }Description
Accumulates elements into a single result. Shortcut for sum: arr.sum.
Example
Loading editor…
Expected output
10 10
When to use?
Sum, product, concatenation.