Skip to content

Instantly share code, notes, and snippets.

@Ebonkuab
Created January 6, 2016 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ebonkuab/9cde6a2d2ac046e3137d to your computer and use it in GitHub Desktop.
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)
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