Module: Enumerable

Defined in:
lib/midwire_common/enumerable.rb

Instance Method Summary collapse

Instance Method Details

#sort_by_frequencyObject

Sort by frequency of occurrence rubocop:disable Style/EachWithObject



4
5
6
7
8
9
10
# File 'lib/midwire_common/enumerable.rb', line 4

def sort_by_frequency
  histogram = inject(Hash.new(0)) do |hash, x|
    hash[x] += 1
    hash
  end
  sort_by { |x| [histogram[x] * -1, x] }
end