Created
May 17, 2013 19:15
-
-
Save procload/5601294 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(given_string) | |
given_arr = given_string.split('') | |
puts "String length: #{given_arr.length}" | |
hsh = {} | |
given_arr.each do |character| | |
hsh[character] = hsh.fetch(character,0) + 1 | |
end | |
hsh.each_pair do |key, val| | |
puts "The character #{key} appears #{val} times." | |
end | |
end | |
count_letters("This is my string, yo. How do you like it?") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment