|
|
|
|
|
by jewbacca
3625 days ago
|
|
> If you are calling #sum on an array of non-integers then you need to provide your own initial value Why? This doesn't seem necessary, but, more importantly, would be inconsistent with #inject's behaviour (if enforced). ---- http://ruby-doc.org/core-2.3.1/Enumerable.html#method-i-inje...: If you do not explicitly specify an initial value for memo, then the first element of collection is used as the initial value of memo |
|
Forcing the use of the additive identity every time, rather than starting with the first element of the collection, is a good way of setting people up to get the correct behaviour on empty collections, even if they don't test for that case.