-
Notifications
You must be signed in to change notification settings - Fork 36
Jack Chester Solutions #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| end | ||
| end | ||
|
|
||
| context 'when string is nonunique, puntuated, with capitalization' do |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rspec also has include matchers too.
https://relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/include-matcher
| @@ -0,0 +1,43 @@ | |||
| require 'rspec' | |||
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 = {} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Thanks for the feedback!
@jaybobo @matt529
Tried to make my tests as well written as possible on this one, please let me know what you think.