-
Notifications
You must be signed in to change notification settings - Fork 90
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
Initial add of the Enumerable problem set #100
base: master
Are you sure you want to change the base?
Conversation
end | ||
|
||
def fetch_the_dog(input) | ||
#implement your solution here | ||
input.find_all { |animal| animal.downcase == "dog" } |
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.
.find_all
works but .select
is what we're looking for here.
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.
They are aliases, and most folks prefer select
.
Here's a style guide many rubyists follow: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
@@ -1,26 +1,26 @@ | |||
|
|||
def capitalize_each_string(input) | |||
#implement your solution here | |||
input.map { | animal | animal.capitalize } |
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.
looks good. are you familiar with ruby's to_proc method? its super common and would help you shorten this a bit.
https://stackoverflow.com/questions/14881125/what-does-to-proc-method-mean
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.
@jaybobo Ahh gotcha. So something more like this input.map(&:capitalize)
?
end | ||
|
||
def fetch_CD_animals(input) | ||
#implement your solution here | ||
input.select { | animal | animal.downcase.start_with?("c", "d") } |
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.
ruby has a cool enumerable called .grep
which is handy here for particular use cases like this one.
https://ruby-doc.org/core-2.5.0/Enumerable.html#method-i-grep
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.
@jaybobo Something more like this input.grep(/^[c,d]/i)
?
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.
Looks good. See my comments.
@jaybobo Please review whenever you have a second.