Ruby - find the key(s) of the largest value(s) of a hash
hash, max, ruby
Solution
If you want all pairs, I would do something like
max = my_hash.values.max
Hash[my_hash.select { |k, v| v == max}]
Problem
I have a hash and I want to return the key(s) (or key/value pair(s)) of the max value(s) of the hash. So, if there is only one true max, it will return that one key; however, if there are multiple key/value pairs with the same value, it will return all of these keys. How can I accomplish this in Ruby? ``` my_hash.max_by {|k,v| v} #only returns one key/value pair ```