Skip to content

Instantly share code, notes, and snippets.

@bil-bas
Forked from anonymous/gist:5939682
Last active December 19, 2015 10:19
Show Gist options
  • Save bil-bas/5939750 to your computer and use it in GitHub Desktop.
Save bil-bas/5939750 to your computer and use it in GitHub Desktop.
puts 'What is the name and path of the file?'
filename = gets.chomp
text = File.read(filename)
freqs = text.scan(/[a-zA-Z]+/).each.with_object(Hash.new(0)) { |word, freqs| freqs[word] += 1 }
freqs = freqs.sort_by {|x,y| -y }
freqs.each {|word, freq| puts "#{word} #{freq}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment