4 ms·
Usually, I think, people write sum with inject: [1,2,3].inject { |s,i| s + i } Which is presumably why sum doesn't exist.
by Locke 18y ago
Usually, I think, people write sum with inject:
[1,2,3].inject { |s,i| s + i }
Which is presumably why sum doesn't exist.
- deleted 18y ago[deleted]
- nc 18y agoWhich is even easier in Ruby 1.9 [1,2,3].inject(:+)