Sum of Array

From Rosetta Code
Revision as of 21:14, 22 January 2007 by rosettacode>Gfannes
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Task
Sum of Array
You are encouraged to solve this task according to the task description, using any language you may know.

Compute the sum of the elements of an Array

Ruby

 ary = [1,2,3,4,5]
 sum = ary.inject{|currentSum,element|currentSum+element}