8/8 Extra Step For Fun


How can we eliminate special characters such as a period "." or a comma "," so our program doesn't count the character as part of the word.


Replace this line with your code.


It's not necessary for this exercise, but if you want to, you could use select.


Thanks for tip nicoekkart. Would you be able to give an example?


Sure, this will filter out all the !:

"a!!b!cd!gh".split('').select{|x| x!='!'}.join()


Thanks... it worked! Used your tip and added a filter to

puts "Enter your text here."
text = gets.chomp
filter = text.split('').select{ |x| x!= "." && x!= "!" && x!= "," }.join()
words = filter.split(' ')
frequencies = Hash.new(0)
words.each { |x| frequencies[x] += 1 }
frequencies = frequencies.sort_by { |k,v| v }
frequencies.each { |k,v| puts "#{k} #{v}" }

PS. If there is a better solution would appreciate any advice.


Could you please explain why you put k,v instead of a,b?