Created
July 28, 2011 21:23
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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