overtone overtone - 2 months ago 7x
Ruby Question

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 }
@sortedInternalLinksHash = @countHash.sort_by { |k,v| !v }

@sortedInternalLinksHash = @countHash.sort_by { |k,v| v }.reverse