Skip to content

Conversation

@andrewpetit
Copy link

@@ -0,0 +1,31 @@

def readFile(file)
return File.read(file)
Copy link
Member

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 ]/,'')
Copy link
Member

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
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 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
Copy link
Member

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
Copy link
Member

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

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