Class: Counts
- Inherits:
-
Object
- Object
- Counts
- Defined in:
- lib/counts.rb
Overview
A method for counting frequency of words in a list
Class Method Summary collapse
Class Method Details
.count(word_list) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/counts.rb', line 4 def self.count(word_list) counts =Hash.new(0) for word in word_list counts[word] +=1 end #counts sorted = counts.sort_by{|w, count| count}.reverse return sorted end |