Array.reduce
reducefunctionif_empty
Documentation
Combines all the elements of a non-empty array using a binary operation. If the array is empty, it returns if_empty.
Arguments
function: A binary operation that takes two items and combines them.if_empty: Value returned if the array is empty.
Examples
Compute the sum of all the elements in an array.
[0, 1, 2].to_array . reduce (+)