Merge pull request #157 from rusikf/rk/fix_recursive_ruby_max
Fix 04_recursive_max on ruby
This commit is contained in:
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user