Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- puts "Give me a sentence: "
- sentence = gets.chomp
- words = sentence.split
- numberoftimes= Hash.new
- words.each {|word| numberoftimes[word] += 1}
- numberoftimes=numberoftimes.sort_by {|word,amount|amount}
- numberoftimes.each do |word,amount|
- puts word + " " + number.to_s
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement