Skip to content

Instantly share code, notes, and snippets.

@jailsonsf
Created April 4, 2023 18:05
Show Gist options
  • Save jailsonsf/bb8fb1db5e22771637b89f3a77fdd45d to your computer and use it in GitHub Desktop.
Save jailsonsf/bb8fb1db5e22771637b89f3a77fdd45d to your computer and use it in GitHub Desktop.
def char_counter(text, char)
text_splited = text.split(' ').join('')
text_splited.each_char.tally[char]
end
puts 'Qual o texto que quer usar:'
text = gets.chomp
puts 'Qual caracter quer contar:'
char = gets.chomp
puts "A letra '#{char}' aparece #{char_counter(text, char)} vezes na frase: '#{text}'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment