Skip to content

Commit cc553c7

Browse files
committed
Find_even completed
1 parent bd155e1 commit cc553c7

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

exercises/find_even.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
# find_even([10,10,10,11,11,11]) == [10,10,10]
1111

1212
def find_even(array)
13+
array1 = []
14+
array.each do |ar|
15+
if ar % 2 == 0
16+
array1.push(ar)
17+
else
18+
return array1
19+
end
20+
21+
end
1322
end
1423

1524
# Note #1
@@ -43,14 +52,15 @@ def find_even(array)
4352

4453
# If the input is the empty array,
4554
# find_even should return the empty array
46-
55+
p find_even([]) == []
4756
# If the input array contains all EVEN numbers,
4857
# find_even should return the input array
4958
p find_even([2, 4, 6, 8, 10]) == [2, 4, 6, 8, 10]
5059

5160
# If the input array contains all ODD numbers,
5261
# find_even should return the empty array
53-
62+
p find_even([3, 5, 7, 9, 11]) == []
5463
# If an even number appears N times in the input array,
5564
# it should appear N times in the the array that find_even returns
65+
p find_even([2, 4, 4, 6, 8, 10]) == [2, 4, 4, 6, 8, 10]
5666
end

0 commit comments

Comments
 (0)