Created
November 27, 2009 04:30
-
-
Save gunn/243821 to your computer and use it in GitHub Desktop.
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 common_words the_words | |
prohibited = %w{i is about an and are as be by come de en this for from} | |
the_result = the_words.gsub(/[^a-z ]/i, "").split(" ").inject(Hash.new(0)) do |hash, w| | |
hash[w] += 1 if !prohibited.include?(w) | |
hash | |
end | |
the_result.sort{ |a,b| b[1] <=> a[1] }.first(10).map{|a,b| a }.join(", ") | |
end | |
p common_words("This is some text. This is some text. Slash development costs.") | |
# To contrast with: http://www.pitchengine.com/brands/runrev/images/33419/PHPvsRevTalkCodeComparison.JPG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment