Created
July 11, 2013 21:29
-
-
Save hassanshamim/5979428 to your computer and use it in GitHub Desktop.
Linq thing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def top10(str) | |
| word_dict = Hash.new{|hash, key| hash[key] = 0 } | |
| str.split.each{ |word| word_dict[word] += 1 } | |
| word_dict.to_a.sort{|a, b| b.last <=> a.last }.take(10).map(&:first) #ugly ugly | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment