Skip to content

Instantly share code, notes, and snippets.

@kejadlen
Created June 9, 2018 19:22
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 kejadlen/aa4f800150e2994d2ae7b43e9ca8b212 to your computer and use it in GitHub Desktop.
Save kejadlen/aa4f800150e2994d2ae7b43e9ca8b212 to your computer and use it in GitHub Desktop.
STOP_WORDS = %w[ the for in ].map(&:downcase)
puts ARGF.read.split(/[^\w]+/)
.map(&:downcase)
.reject {|word| STOP_WORDS.include?(word) }
.each.with_object(Hash.new(0)) {|word, freqs| freqs[word] += 1 }
.sort_by {|_, freq| freq }
.reverse
.take(25)
.map {|word, freq| "#{word} - #{freq}" }
.join("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment