Ruby:Sum an Array

From Progzoo
Jump to: navigation, search

You can add the numbers in the array [6,7,29] using a loop.

An alternative:

a = [6,7,29]
puts a.inject(0){|b,i| b+i}
[Font] [Default] [Show] [Resize] [History] [Profile]