I have a hash where the values are numbers. After I build the hash I
want to get the key back that has the largest number as a value.
So for example:
I build the hash and add to the values -
results = Hash.new(0) score = find_score score.points.each do |point| result_score = ResultScore.find(:first, point) if results.has_key?(result_score.result_id) results[result_score.result_id] =+ result_score_points else results[result_score.result_id] = result_score_points end end
Now what I want to do is get the key back out of the hash ‘results’ with
the highest value.
I thought about inverting the hash and then sorting the keys. Does ruby
sort integers as keys?