-
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
Solve all Enumerables challenges #107
base: master
Are you sure you want to change the base?
Conversation
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 comments.
challenge.rb
Outdated
end | ||
|
||
def no_dogs_allowed(input) | ||
input = input.dup |
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.
challenge.rb
Outdated
end | ||
|
||
def count_the_animals(input) | ||
input.length |
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.
length isn't actually an enumerable but there's good reasons for familiarizing yourself with it and it's counterparts (eg. .size
, .count
) use cases.
see this article: http://batsov.com/articles/2014/02/17/the-elements-of-style-in-ruby-number-13-length-vs-size-vs-count/
https://ruby-doc.org/core-2.5.1/Enumerable.html#method-i-count
end | ||
|
||
def fetch_the_first_two(input) | ||
input[0, 2] |
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.
challenge.rb
Outdated
end | ||
|
||
def fetch_CD_animals(input) | ||
input.find_all { |animal| animal.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.
challenge.rb
Outdated
end | ||
|
||
def fetch_the_dog(input) | ||
input.find_all { |animal| animal == "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.
this works. there's also .select
.
see: https://ruby-doc.org/core-2.5.1/Enumerable.html#method-i-select
@jaybobo