-
Notifications
You must be signed in to change notification settings - Fork 36
Andrew Petit Solution #44
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
| @@ -0,0 +1,31 @@ | |||
|
|
|||
| def readFile(file) | |||
| return File.read(file) | |||
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.
No need for an explicit return here.
With regards to method names, lower snakecase is generally the rule.
https://github.com/bbatsov/ruby-style-guide
|
|
||
|
|
||
| def getWords(text) | ||
| text.gsub!(/[^A-Za-z ]/,'') |
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.
.gsub! mutates your data. how about using i.gsub and returning a modified copy instead?
|
|
||
| def getWords(text) | ||
| text.gsub!(/[^A-Za-z ]/,'') | ||
| data = Hash.new |
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 and then build it up is a good time to ask could I use .reduce or .map.
In this case, there's an even better option .each_with_object. Try refactoring and using it instead.
https://ruby-doc.org/core-2.4.1/Enumerable.html#method-i-each_with_object
| text.gsub!(/[^A-Za-z ]/,'') | ||
| data = Hash.new | ||
| temparray = text.to_s.split(" ").map(&:to_s) | ||
| for word in temparray |
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 won't see a lot of "for loops" used in ruby. There's usually a better option available if you sniff around in...
https://ruby-doc.org/core-2.4.1/Enumerable.html
https://ruby-doc.org/core-2.4.1/Array.html
https://ruby-doc.org/core-2.4.1/Hash.html
https://ruby-doc.org/core-2.4.1/Times.html
| require_relative '../lib/readfile.rb' | ||
|
|
||
| describe 'Number of words' do | ||
| it 'get words return the proper number' 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.
2 spaces. https://github.com/bbatsov/ruby-style-guide
Check out this great site on rspec best practices.
www.betterspecs.org
@jaybobo