fix 04_recursive_max on ruby

This commit is contained in:
Ruslan Korolev
2020-01-17 18:26:21 +02:00
parent d8da439590
commit 891eec2873

View File

@@ -1,10 +1,12 @@
def max(list)
if list.empty?
nil
elsif list.length == 1
numbers[0]
return nil if list.empty?
if list.length == 1
list[0] # base case
else
sub_max = max(list[1..-1])
list[0] > sub_max ? list[0] : sub_max
end
end
puts max([2,3,8,5,5])