Created
May 19, 2014 12:00
-
-
Save shinokada/05c07cf68f3bea08cf19 to your computer and use it in GitHub Desktop.
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
| # return max hash key-value pair | |
| def largest_hash_key(hash) | |
| hash.max_by{|k,v| v} | |
| end | |
| hash = {"ZZ" => 0, "CA"=>2, "MI"=>1, "NY"=>1} | |
| p largest_hash_key(hash) # return ["CA", 2] | |
| # return largest hash key pair | |
| p hash.max | |
| # return largest hash key pair | |
| p hash.max_by{|x, v| x} | |
| # return largest hash value pair | |
| p hash.max_by{|x, v| v} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment