Created
May 16, 2014 22:09
-
-
Save IrakliJani/813f4f81bed219b58512 to your computer and use it in GitHub Desktop.
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 top_3_words(text) | |
| text | |
| .gsub(/[^A-Za-z ']+/, '') | |
| .split(/\s+/) | |
| .inject(Hash.new 0) { |v, w| v[w.downcase] += 1; v } | |
| .sort_by { |w, c| c } | |
| .reverse | |
| .map { |v, k| v } | |
| .reject(&:empty?) | |
| .select { |e| e =~ /\w/i } | |
| .first(3) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment