Array sum

Tagged with Ruby

Language: Ruby

Sums up the elements in an array.

View as text



   # Sums up the elements in the array
   def sum
      my_array.inject(0){|total,item| total + item}
   end



Last updated at 13:13 PM on Sep 09, 2008 by Brian Hogan

SnippetStash costs money to host and develop. The service is free for everyone to use
but if you found it useful please consider making a small donation.