How to find the max value, then the key of a hash in ruby
my_hash = {:a => 1, :b => 12, :c => 23, :d => 3 }
max_value = my_hash.values.max #23
max_value_key = my_hash.key(max_value) #:c
This is a tumblelog, kinda like a blog but with short-form, mixed-media posts with stuff I like. Scroll down a bit to start reading, or a bit more to read more about me.
my_hash = {:a => 1, :b => 12, :c => 23, :d => 3 }
max_value = my_hash.values.max #23
max_value_key = my_hash.key(max_value) #:c