Skip to content
Open
Changes from 1 commit
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
79 changes: 41 additions & 38 deletions challenge.rb
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" }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

end

def no_dogs_allowed(input)
input = input.dup
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown
Member

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]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

The 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"]