Skip to content

Instantly share code, notes, and snippets.

@stupeters187
Created March 29, 2016 16:26
Show Gist options
  • Save stupeters187/00f14fd355d1a0edd887 to your computer and use it in GitHub Desktop.
Save stupeters187/00f14fd355d1a0edd887 to your computer and use it in GitHub Desktop.
# # Find the maximum
# def maximum(arr)
# arr.max
# end
def number(arr)
a = "".to_i
arr.each do |b|
if a < b
a = b
end
end
a
end
# expect it to return 42 below
result = number([2, 42, 22, 02])
puts "max of 2, 42, 22, 02 is: #{result}"
# # expect it to return nil when empty array is passed in
# 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