Skip to content

Instantly share code, notes, and snippets.

/most.rb Secret

Created February 10, 2015 18:33
Show Gist options
  • Save anonymous/65ae37181eec3a3b2765 to your computer and use it in GitHub Desktop.
Save anonymous/65ae37181eec3a3b2765 to your computer and use it in GitHub Desktop.
def most_common_letter(string)
array = string.split('')
new_array = []
array.map do |x|
new_array << [x, array.count(x)]
array.delete(x)
end
new_array.sort{|a,b| b[1]<=>a[1]}
new_array[0]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment