Created
January 6, 2016 23:44
-
-
Save Ebonkuab/9cde6a2d2ac046e3137d to your computer and use it in GitHub Desktop.
Ruby code for counting the number of characters in a string without counting space (LIGHTHOUSE LABS DEV BOOTCAMP)
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(user_input) | |
counted = {} | |
characters = user_input.split("") | |
for char in characters | |
if char == " " | |
next | |
elsif counted.has_key? char | |
counted[char] =counted[char] + 1 | |
else | |
counted[char]= 1 | |
end | |
end | |
#for user input do a split of the string | |
#identify the chracters going through the string | |
#do a count of each character | |
puts counted | |
end | |
puts "please write a sentence" | |
user_input = gets.chomp | |
count_letters(user_input) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment