Ruby:Hashの値でソートしたArray

Ruby 1.8.7で。

hash.map { |k, v| { :name => k, :count => v } }.sort { |a, b| b[:count] <=> a[:count] }

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <img localsrc="" alt="">