Skip to content

Instantly share code, notes, and snippets.

@leeacto
Created July 3, 2013 16:19
Show Gist options
  • Select an option

  • Save leeacto/5920004 to your computer and use it in GitHub Desktop.

Select an option

Save leeacto/5920004 to your computer and use it in GitHub Desktop.
def mode(array)
el_count = {}
array.each do |n|
if el_count.has_key?(n)
el_count[n] = el_count[n] + 1
else
el_count[n] = 1
end
end
el_count.select { |k, v| v == el_count.values.max }.keys
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment