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

Initial add of the Enumerable problem set #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kapschy
Copy link

@kapschy kapschy commented Apr 26, 2018

@jaybobo Please review whenever you have a second.

end

def fetch_the_dog(input)
#implement your solution here
input.find_all { |animal| animal.downcase == "dog" }
Copy link
Member

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.

Copy link
Member

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

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

Copy link
Author

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") }
Copy link
Member

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

Copy link
Author

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) ?

Copy link
Member

@jaybobo jaybobo left a 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.

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.

3 participants