-
Notifications
You must be signed in to change notification settings - Fork 86
Solve all Enumerables challenges #107
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,43 @@ | ||
|
|
||
| def capitalize_each_string(input) | ||
| #implement your solution here | ||
| end | ||
|
|
||
| def fetch_the_dog(input) | ||
| #implement your solution here | ||
| end | ||
|
|
||
| def no_dogs_allowed(input) | ||
| #implement your solution here | ||
| end | ||
|
|
||
| def count_the_animals(input) | ||
| #implement your solution here | ||
| end | ||
|
|
||
| def fetch_the_first_two(input) | ||
| #implement your solution here | ||
| end | ||
|
|
||
| def fetch_CD_animals(input) | ||
| #implement your solution here | ||
| end | ||
|
|
||
| ## DO NOT CHANGE CODE BELOW THIS LINE ## | ||
|
|
||
| animals = ["cat", "moose", "dog", "bird"] | ||
|
|
||
| p capitalize_each_string(animals) == ["Cat", "Moose", "Dog", "Bird"] | ||
|
|
||
| p fetch_the_dog(animals) == ["dog"] | ||
|
|
||
| p no_dogs_allowed(animals) == ["cat", "moose", "bird"] | ||
|
|
||
| p count_the_animals(animals) == 4 | ||
|
|
||
| p fetch_the_first_two(animals) == ["cat", "moose"] | ||
|
|
||
| p fetch_CD_animals(animals) == ["cat", "dog"] | ||
| input.map { |item| item.capitalize } | ||
| end | ||
|
|
||
| def fetch_the_dog(input) | ||
| input.find_all { |animal| animal == "dog" } | ||
| end | ||
|
|
||
| def no_dogs_allowed(input) | ||
| input = input.dup | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| input.delete("dog") | ||
| return input | ||
| end | ||
|
|
||
| def count_the_animals(input) | ||
| input.length | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. 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] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| end | ||
|
|
||
| def fetch_CD_animals(input) | ||
| input.find_all { |animal| animal.start_with?("c", "d")} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| end | ||
|
|
||
| ## DO NOT CHANGE CODE BELOW THIS LINE ## | ||
|
|
||
| animals = ["cat", "moose", "dog", "bird"] | ||
|
|
||
| p capitalize_each_string(animals) == ["Cat", "Moose", "Dog", "Bird"] | ||
|
|
||
| p fetch_the_dog(animals) == ["dog"] | ||
|
|
||
| p no_dogs_allowed(animals) == ["cat", "moose", "bird"] | ||
|
|
||
| p count_the_animals(animals) == 4 | ||
|
|
||
| p fetch_the_first_two(animals) == ["cat", "moose"] | ||
|
|
||
| p fetch_CD_animals(animals) == ["cat", "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