Skip to content

Instantly share code, notes, and snippets.

@shinokada
Created May 19, 2014 13:12
Show Gist options
  • Save shinokada/da19c4be6dbf909b1b8f to your computer and use it in GitHub Desktop.
Save shinokada/da19c4be6dbf909b1b8f to your computer and use it in GitHub Desktop.
arr = [1, 1, 1, 2, 3]
freq = arr.inject(Hash.new(0)) { |h,v| h[v] += 1; h }
#=> {1=>3, 2=>1, 3=>1}
arr.max_by { |v| freq[v] }
#=> 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment