Last active
August 18, 2017 22:18
-
-
Save lesleh/113e484e1f31eebeb5e35237ed68c174 to your computer and use it in GitHub Desktop.
Count the number of occurrences of each unicode character in a bunch of files
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
require 'json' | |
all_chars = {} | |
Dir["**/*.md"].each do |file| | |
character_data = IO.read(file).each_char.each_with_object(Hash.new(0)) do |word,counts| | |
counts[word] += 1 | |
end | |
all_chars.merge!(character_data) do |_, oldval, newval| | |
oldval + newval | |
end | |
end | |
all_chars.sort_by {|_key, value| value}.reverse.each do |x| | |
puts "#{x[0]} - #{x[1]}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment