Last active
November 19, 2015 07:41
-
-
Save DavidGoussev/268beafc067f6f26c233 to your computer and use it in GitHub Desktop.
Top-Three in Array by Length
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) | |
| 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