Skip to content

Instantly share code, notes, and snippets.

@skalibog
Created August 9, 2019 07:22
Show Gist options
  • Save skalibog/aed1d3618d56c9f84984293a7e526c62 to your computer and use it in GitHub Desktop.
Save skalibog/aed1d3618d56c9f84984293a7e526c62 to your computer and use it in GitHub Desktop.
def parse(text)
arr = text.split(/[,.!? ]/).reject(&:empty?)
a = arr.map(&:downcase).each_with_object(Hash.new(0)) do |k, v|
v[k] += 1
end
return [] if a.count < 3
p a.sort_by { |_, v| v }.reverse[0...3]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment