I am trying to sum array values. Here's my code:
def addArray(array)
for i in array do
sum += i
end
end
addArray([1,3,6,8,7,10]);
What's wrong with this thought process?
I know there are other ways to do this such as using reduce
or even sum
, but am I not just adding the next value to sum
every iteration?