Created
December 10, 2013 14:04
-
-
Save jmoon90/7891047 to your computer and use it in GitHub Desktop.
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
| class WordCount | |
| def initialize(sentence) | |
| @sentence = sentence | |
| end | |
| def frequency | |
| word_counter = Hash.new(0) | |
| @sentence.split(' ').each do |word| | |
| word_counter[word.downcase] += 1 | |
| end | |
| word_counter | |
| end | |
| end |
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_relative "word_count" | |
| require "rspec" | |
| describe WordCount do | |
| require 'pry' | |
| it "count the frequency of each word" do | |
| expect(WordCount.new('Toy boat toy boat toy boat').frequency).to eql( { 'toy' => 3, 'boat' => 3 } ) | |
| end | |
| it 'ignores non word or number characteristics' | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment