Created
April 1, 2014 14:27
-
-
Save s-osa/9915236 to your computer and use it in GitHub Desktop.
This file contains 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
def count_by_word(string) | |
hash = Hash.new(0) | |
string.split(' ').each{|word| hash[word] += 1} | |
hash | |
end | |
describe "count by word" do | |
it "counts by word" do | |
expect(count_by_word("no ruby no life")).to eq("no" => 2, "life" => 1, "ruby" => 1) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment