Skip to content

Instantly share code, notes, and snippets.

@betawaffle
Created July 28, 2011 21:23
Show Gist options
  • Save betawaffle/1112597 to your computer and use it in GitHub Desktop.
Save betawaffle/1112597 to your computer and use it in GitHub Desktop.
Write a ruby method that takes in an array of integers and returns back the largest integer. Do not use .max
def biggest(list)
list.inject do |a, b|
a < b ? b : a
end
end
# Even more concise:
def biggest(list)
list.inject { |a, b| a < b ? b : a }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment