Skip to content

Instantly share code, notes, and snippets.

@kenrett
Created February 27, 2013 21:26
Show Gist options
  • Save kenrett/5051882 to your computer and use it in GitHub Desktop.
Save kenrett/5051882 to your computer and use it in GitHub Desktop.
def mode(array)
a = array.inject(Hash.new(0)) { |key, value| key[value] += 1; key }
array.sort_by { |value| a[value] }.last
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment