Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def top_3_words(text)
- text
- .split(/\s+/)
- .inject(Hash.new(0)) { |key, val| key[val.downcase] += 1; key }
- .sort_by { |key, val| val }
- .collect! { |v, k| v }
- .reject(&:empty?)
- .select { |e| e =~ /\w/i }
- .reverse
- .first(3)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement