Skip to content

Instantly share code, notes, and snippets.

@scottdomes
scottdomes / max.rb
Last active March 1, 2016 19:35 — forked from davidvandusen/max.rb
# Find the maximum
def maximum(arr)
arr.inject { |x, max| x > max ? x : 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