8/8 Extra Step For Fun


#1



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.


https://www.codecademy.com/en/courses/ruby-beginner-en-693PD/0/8?curriculum_id=5059f8619189a5000201fbcb


Replace this line with your code.


#2

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


#3

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


#4

Sure, this will filter out all the !:

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

#5

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.reverse!
frequencies.each { |k,v| puts "#{k} #{v}" }

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


#6

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