Skip to content

Instantly share code, notes, and snippets.

@Jauny
Created August 16, 2012 19:19
Show Gist options
  • Select an option

  • Save Jauny/3372849 to your computer and use it in GitHub Desktop.

Select an option

Save Jauny/3372849 to your computer and use it in GitHub Desktop.
calculate the mode of an array
def mode(array)
h = Hash.new
array.uniq.each do |x|
h[x] = array.count(x)
end
h.select{|k,v| v == h.values.max }.map{|i| i[0] }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment