reduce with operator : reduce « Range « Ruby






reduce with operator


sum = (1..5).reduce(:+)                    # => 15
prod = (1..5).reduce(:*)                   # => 120
letters = ('a'..'e').reduce("-", :concat)  # => "-abcde"

 

Related examples in the same category