Skip to content

Instantly share code, notes, and snippets.

@DavidGoussev
Last active November 19, 2015 07:41
Show Gist options
  • Select an option

  • Save DavidGoussev/268beafc067f6f26c233 to your computer and use it in GitHub Desktop.

Select an option

Save DavidGoussev/268beafc067f6f26c233 to your computer and use it in GitHub Desktop.
Top-Three in Array by Length
def top_3_words(text)
words = text.split(/('\w+)|(\w+'\w+)|(\w+')|(\w+)/)
words.max_by(3) {|x| words.length }
end
def top_3_words(text)
words = text.split(/[^a-zA-Z0-9']+/)
words.each{|word| word.downcase!}
puts words
words.sort_by{|word| words.count(word)}.reverse.uniq.first(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment