forked from paircolumbus/MoreEnumerables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchallenge.rb
40 lines (26 loc) · 761 Bytes
/
challenge.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def capitalize_each_string(input)
input.map {|a| a.capitalize}
end
def fetch_the_dog(input)
input.select {|a| a.casecmp("dog") == 0}
end
def no_dogs_allowed(input)
input.reject {|a| a.casecmp("dog") == 0}
end
def count_the_animals(input)
input.count
end
def fetch_the_first_two(input)
input.take(2)
end
def fetch_CD_animals(input)
input.grep(/^[cdCD].*/)
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"]