Skip to content

Instantly share code, notes, and snippets.

@katherholt
Created June 21, 2016 21:06
Show Gist options
  • Save katherholt/4022b7f825357f84111a96a5a6b559fe to your computer and use it in GitHub Desktop.
Save katherholt/4022b7f825357f84111a96a5a6b559fe to your computer and use it in GitHub Desktop.
def maximum(arr)
while arr.length>1
arr.each do |i|
if i+1>i
arr.delete(i)
end
end
end
if arr.length==0
return nil
else
return arr[0].to_i
end
end
result = maximum([2, 42, 22, 02])
puts "max of 2, 42, 22, 02 is: #{result}"
result = maximum([])
puts "max on empty set is: #{result.inspect}"
result = maximum([-23, 0, -3])
puts "max of -23, 0, -3 is: #{result}"
result = maximum([6])
puts "max of just 6 is: #{result}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment