Module: Enumerable
- Defined in:
- lib/midwire_common/enumerable.rb
Instance Method Summary collapse
-
#sort_by_frequency ⇒ Object
Sort by frequency of occurrence.
Instance Method Details
#sort_by_frequency ⇒ Object
Sort by frequency of occurrence
3 4 5 6 |
# File 'lib/midwire_common/enumerable.rb', line 3 def sort_by_frequency histogram = inject(Hash.new(0)) {|hash, x| hash[x] += 1; hash} sort_by {|x| [histogram[x] * -1, x]} end |