Skip to content
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

. #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

. #39

wants to merge 2 commits into from

Conversation

matthewlee07
Copy link

No description provided.

parser.rb Outdated
return :yes
end
}
return :no
Copy link
Contributor

Choose a reason for hiding this comment

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

First, some trivial little style things:

  • for multi-line blocks, prefer the do...end syntax.
  • use return only for early, i.e. not on the last line of the method
  • it looks like you're getting the triple-equals from javascript. In ruby, that is actually the case-comparison operator, which happens to work in this case, but will give you unexpected behavior in other cases. What you want is the double-equals.
  • in the file below, you're replacing all of the single quotes with double quotes. Ruby-ists typically prefer single quotes to double quotes, when possible. Double quotes in ruby allow for interpolation and various other goodies, and so using single quotes makes it super obvious to readers of code that there's nothing funky going on inside (assuming that there isn't).

Copy link
Contributor

Choose a reason for hiding this comment

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

Slightly more substantive feedback:

  • is there a way you could use the any? method instead of each?
  • you've got the regex, and you've got the splitting. Can't you just use the regex for the splitting?
  • does \b improve your regex?

Copy link
Contributor

Choose a reason for hiding this comment

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

Finally, I think there's a one-liner solution here. It might involve:

  • making better use of your regex, and
  • a ternary for the :yes and :no

Copy link
Author

@matthewlee07 matthewlee07 Nov 7, 2018

Choose a reason for hiding this comment

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

I don't know how to do another pull request, but this is the updated code:

def word_in_string?(word, string)
new_string = string.downcase.gsub(/[^a-z]/, " ").split(" ")
new_string.any? { |string| word == string } ? :yes : :no
end

I'm not sure about the regex, I just looked up an example

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, instead of another pull request, you'd typically just tack on another commit (like you did).

You've hit a bunch of my concerns above, but not all of them. Take another read through.

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