Quotes help make search much faster. Example: "Practice Makes Perfect"

Tuesday, November 20, 2012

Codecademy: "Sorting the Hash"


#sample solution


puts "Enter a phrase: "
text = gets.chomp
words = text.split(" ")
frequencies = Hash.new(0)
words.each {|element| frequencies[element] += 1}
frequencies = frequencies.sort_by {|a,b| b}
frequencies = frequencies.reverse!

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts