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