Hello I\'m trying to find the largest value in my hash. I made a search in google and I found this code:
def largest_hash_key(hash)
key = hash.sort{|a,b|
Here is another way of doing what you want. This will find all the keys with the maximum value:
h = {"n" => 100, "m" => 100, "y" => 300, "d" => 200, "a" => 0, "z" => 300}
max = h.values.max
output_hash = Hash[h.select { |k, v| v == max}]
puts "key(s) for the largest value: #{output_hash.keys}"
#=>key(s) for the largest value: ["y", "z"]