From: Harry Kakueki Date: 2010-09-09T20:48:44+09:00 Subject: Re: Key Associated w/ Maximum Value in Hash On Thu, Sep 9, 2010 at 11:57 AM, Timothy Baron wrote: > Simple question:  what's the cleanest way to retrieve a key associated > with the maximum value of a hash.  For instance, how do I retrieve 'b' > from the following example: > > hash = Hash.new > hash['a']=4 > hash['b']=10 > hash['c']=7 > -- What if you have more than one max? h = {'a'=>4,'b'=>10,'c'=>7,'d' => 10} p h.select{|x,i| i==h.values.max}.keys #> ["b", "d"] Harry