VladikOtez

Search

May 22nd, 2017
149
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def top_3_words(text)
  2.   text
  3.   .split(/\s+/)
  4.   .inject(Hash.new(0)) { |key, val| key[val.downcase] += 1; key }
  5.   .sort_by { |key, val| val }
  6.   .collect! { |v, k| v }
  7.   .reject(&:empty?)
  8.   .select { |e| e =~ /\w/i }
  9.    .reverse
  10.    .first(3)
  11. end
RAW Paste Data