Skip to content

Conversation

@jack-chester
Copy link

@jaybobo @matt529

Tried to make my tests as well written as possible on this one, please let me know what you think.

end
end

context 'when string is nonunique, puntuated, with capitalization' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can actually nests contexts.


context 'when string is nonunique, puntuated, with capitalization' do
it 'returns proper array' do
expect(counter.countWords("GOOSE! Maverick Goose goose, Iceman (icEman)")).to eq(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,43 @@
require 'rspec'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love the fact that you wrote tests for this. 👍

class Counter

def countWords(text)
text = text.downcase.gsub(/[^a-z' ]/, '') #make lowercase and only keep allowed characters
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the indentation is might funky here, eh?

def countWords(text)
text = text.downcase.gsub(/[^a-z' ]/, '') #make lowercase and only keep allowed characters
raw_words = text.split(" ")
count = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anytime you initialize a new object just to build it up later is a good time to think about using .map or .reduce.

in this case .reduce or .each_with_object is the way you want to go here. These would also simplify your code greatly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 bookmarked the Ruby enumerable documentation

count.sort_by{ |k, v| -v}
end

def printCount(path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love the encapsulation. nitpick: keep in mind that lower snakecase is preferred by rubyists

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants