New to Ruby - undefined method error
def sum(arr = [1,2,3,4,5])
addedUp = 0
i = 0
while i < arr.length
addedUP += arr[i]
end
return addedUp
end
The goal is to define a method sum( arr) which takes an array of integers
as an argument and returns the sum of its elements. For some reason I keep
getting an 'undefined method `sum' for main:Object' error.
No comments:
Post a Comment