Skip to content

Instantly share code, notes, and snippets.

@EdDeAlmeidaJr
Last active May 14, 2016 21:37
Show Gist options
  • Save EdDeAlmeidaJr/60d0b80cd916cf06897e183dc7c6d9d2 to your computer and use it in GitHub Desktop.
Save EdDeAlmeidaJr/60d0b80cd916cf06897e183dc7c6d9d2 to your computer and use it in GitHub Desktop.
def most_common_letter(string)
h = Hash.new
characters = string.chars.each do |c|
if (h[c].nil?) then
h[c] = 1
else
h[c] = h[c]+1
end
end
maxk = nil
maxc = -1
h.each do |k,v|
if (v > maxc) then
maxk = k
maxc = v
end
end
[maxk , maxc]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment