Skip to content

Instantly share code, notes, and snippets.

@davidvandusen
Forked from kvirani/README.md
Created May 5, 2015 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 284 You must be signed in to fork a gist
  • Save davidvandusen/945b67f0ac4775e03afd to your computer and use it in GitHub Desktop.
Save davidvandusen/945b67f0ac4775e03afd to your computer and use it in GitHub Desktop.
# Find the maximum
def maximum(arr)
arr.max
end
# expect it to return 42 below
result = maximum([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