Last active
May 14, 2016 21:49
-
-
Save EdDeAlmeidaJr/b5e9dfbc619c58f39e5d708f4de57da8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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