Closed berniechiu closed 4 years ago
Wonder why some of the approved PRs not merging lol ~
There are at least 2 more ways of doing the same:
arr.sum # available as of Ruby 2.4
arr.inject(:+)
Also when you do summing you better pass initial memo:
arr = []
arr.sum # => 0
arr.inject(:+) # => nil
arr.inject(0, :+) # => 0
arr.inject(&:+) # => nil
arr.inject(0, &:+) # => 0
TBH IMO all that part should be completely rewritten. There's no point to refer rubies 1.x - they are EOL long time ago.
OMG, 30x+ difference :o
Objective
Since some Ruby beginners still write aggregations without inject, it's good to show them a benchmark on different usage that might occur to them.
Feature