E
Eduard Llull
Too many solvers not providing additional problems!
Here's another... Assuming you have an array of numeric data, write a
method that returns an array of progressive sums. That is:
prog_sum( [1, 5, 13, -6, 20] ) => [1, 6, 19, 13, 33]
def prog_sum(ary)
ary.inject([0, []]) {|(s, a), i| [s+i, a<<(s+i)]}.last
end
And what about
def prog_sum(array)
sum = 0; array.collect { |e| sum+=e }
end