Skip to content

Instantly share code, notes, and snippets.

@rvbsanjose
Created August 16, 2012 20:16
Show Gist options
  • Save rvbsanjose/3373261 to your computer and use it in GitHub Desktop.
Save rvbsanjose/3373261 to your computer and use it in GitHub Desktop.
calculate the mode of an array
def mode(array)
array.drop_while {|x| array.count(x) < array.count(x + 1) }.select {|x| array.count(x) > 1}.uniq
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment