Reputation: 5363
I get:
Untitled 5.rb:16: syntax error, unexpected end-of-input, expecting
keyword_end
even though I closed the if
/else
statement and def
with end
:
def max_2_sum(int_collection)
sum = 0
if int_collection.empty?
sum
else if int_collection.count == 1
int_collection.first
else
sum = int_collection.sort[-1] + int_collection.sort[-2]
end
end
int_collection = [4,3,9]
puts max_2_sum(int_collection)
Upvotes: 0
Views: 502
Reputation: 12320
your code should be like below
def max_2_sum(int_collection)
sum = 0
if int_collection.empty?
sum
elsif int_collection.count == 1
int_collection.first
else
sum = int_collection.sort[-1] + int_collection.sort[-2]
end
end
Upvotes: 0