-
-
Save rh0delta/67b24342c9e4a10ba5e8 to your computer and use it in GitHub Desktop.
Character Counter
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 count_letters(string) | |
@letters = {} | |
string.gsub(/\s+/, "").each_char do |letter| | |
unless @letters[letter] | |
@letters[letter] = 1 | |
else | |
@letters[letter] += 1 | |
end | |
end | |
@letters | |
end | |
puts count_letters("lighthouse in the house...") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment