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

Completed Challenge #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ PLATFORMS
DEPENDENCIES
pry
rspec

BUNDLED WITH
1.10.3
7 changes: 7 additions & 0 deletions parser.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
def word_in_string?(word, string)
# implement with your code here
words = string.scan /(^|[^a-zA-Z])#{Regexp.quote(word)}($|[^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.

Nice! This is an interesting solution, though you can simplify the [^a-zA-Z] segments of your regex by using \s (represents any whitespace character) instead.

case words.count>0
when true
:yes
else
:no
end
Copy link
Member

Choose a reason for hiding this comment

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

You don't need a case statement if you only have two conditions. I would recommend using Ruby's ternary operator like this (instead of the previous 6 lines of code):

words.count > 0 ? :yes : :no

end