Skip to content

Instantly share code, notes, and snippets.

@gunn
Created November 27, 2009 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gunn/243821 to your computer and use it in GitHub Desktop.
Save gunn/243821 to your computer and use it in GitHub Desktop.
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