reduce / inject (Ruby)

reduce (alias inject) combines all elements of a collection into a single value by repeatedly applying a block, carrying an accumulator. It's used for sums…