Skip to content

Instantly share code, notes, and snippets.

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