refactor logic for counting each unique word
second iteration
Use Enumerable#each_with_object. :)