Created
March 3, 2015 12:41
-
-
Save ruckuus/19cbfcb3d254ba87b918 to your computer and use it in GitHub Desktop.
This file contains 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
words = [ | |
'apple', | |
'banana', | |
'banana', | |
'foo', | |
'ruby', | |
'apple', | |
'piston', | |
'eagle', | |
'lemon', | |
'apple', | |
'banana', | |
'ruby' | |
] | |
result = Hash.new | |
words.map do |x| | |
result[x] = result[x].to_i + 1 | |
end | |
r = result.sort_by { |word, count| count}.reverse.take(3) | |
puts r.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment