I have an array of integers.
For example:
array = [123,321,12389]
Is there any nice way to get the sum of them?
I know, that
sum = 0
array.each { |a| sum+=a }
would work.
| |||||
start a bounty
<script></script>
|
| |||||||||
|
Add sum to the Array class
Then do fun stuff like:
| |||||||||
|
Alternatively (just for comparison), if you have Rails installed (actually just ActiveSupport):
| |||||
|
Or try the ruby 1.9 way
| |||||||||||||||||||||
|