Last active
August 30, 2016 10:08
-
-
Save vicovictor/be9a4e1d2e3ade553e35cb2cb7d6c4a5 to your computer and use it in GitHub Desktop.
PROD-264: Frequency of searches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
searches = %w( | |
AK | |
AK | |
AK,AR,CA,CT,DE,DC | |
AL | |
AL | |
) | |
searches_formatted = searches.join(",").split(",") | |
freq = searches_formatted.inject(Hash.new(0)) { |h,v| h[v] += 1; h }.sort_by {|_key, value| value}.reverse.to_h | |
freq.each_pair do |key, value| | |
puts "#{key} - #{value}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment