Skip to content

Instantly share code, notes, and snippets.

@vicovictor
Last active August 30, 2016 10:08
Show Gist options
  • Save vicovictor/be9a4e1d2e3ade553e35cb2cb7d6c4a5 to your computer and use it in GitHub Desktop.
Save vicovictor/be9a4e1d2e3ade553e35cb2cb7d6c4a5 to your computer and use it in GitHub Desktop.
PROD-264: Frequency of searches
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