Adjacent Sum problem

I’m unsure why my code here doesn’t work and gives back undefined. Can anyone offer an explanation? Thanks!

I don’t want to just give you the answer but I will give you a hint! Indices versus length

You are attempting to add a number and Nil.

A couple things to keep in mind.
Array#each_with_index is an enumerable method that iterates through the array.
arr = [1, 2 , 3]
i = 0
while i < arr.length - 1
__#do stuff here, where current element can be accessed with arr[i]
__i += 1
end
is equivalent to
arr = [1, 2 , 3]
arr.each_with_index do |ele, idx|
__#do stuff here, where current element can be accessed with ele, or arr[idx]
end
Arrays are accessed by their indexes
arr = [“a”, “b”, “c”]
arr[0] => “a”
arr[1] => “b”
arr[2] => “c”
arr[3] => nil
arr[4] => nil

arr.length => 3

In Ruby, you cannot add a Number to a String, or a nil to a number, or a nil to a String, because they are incompatible types and Ruby does not want to convert a nil to a zero implicitly to match with a number because you might not mean for a nil to be a 0, so instead it yells at you for your own benefit.