reversing hash.sort_by in ruby
Simple enough but Im drawing a blank on it.
@sortedHash = @otherHash.sort_by { |k,v| v }
This stores the has based on key value in ascending order. in other words first value in hash is lowest. How do i reverse (descending order) it so that the highest value is at the top?
@sortedInternalLinksHash = @countHash.sort_by { |k,v| -v }
@s开发者_JS百科ortedInternalLinksHash = @countHash.sort_by { |k,v| !v }
@sortedInternalLinksHash = @countHash.sort_by { |k,v| v }.reverse
Also you can use:
@sortedInternalLinksHash = @countHash.sort_by { |_,v| - v }
精彩评论