I'm trying to write code that will take an array and give back the SUM of the array. First, is this the correct way to place the numbers into an array? It seems like there may be a problem with that based on the error.
def total(num)
x = []
x << num
puts x.inject(0){|a,b|a+b}
end
Looks like a have a few problems here. First, I get this error when I call the method with sum([3,2,41,2])
:
`total': wrong number of arguments (5 for 1) (ArgumentError) from calculator.rb:11
I also recall getting a error: cant't covert fixnum into array