+ 3

For Ruby -> Collection -> Letter frequency counter

how can we make it so it will print / puts only the letters that exist in the phrase and not all the alphabet? what if statement shall we use? i thought and tried something like the one that has the question following this lesson but it didn't work. thanks to whom ever will help. :-)

13th Nov 2016, 9:41 AM
Pantelis
Pantelis - avatar
1 Resposta
+ 1
freqs ={} freqs.default = 0 text = "I like Ruby, this is my favorite on Sololearn!!" text.each_char { |char| freqs[char] += 1} puts freqs
12th Dec 2016, 5:18 PM
Benedek Máté Tóth
Benedek Máté Tóth - avatar