...

/

Exercise 5: Extract even elements from array

Exercise 5: Extract even elements from array

How would you extract the even elements from the array?

Problem Statement

If you are given an array, can you extract elements so that you get even elements?

NOTE: You CAN NOT change the returning statement in the code.

Example

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
result = [2, 4, 6, 8, 10]

Try if yourself

Press + to interact
def even_elements(input_array)
result = []
# Write - Your - Code
return result
end

Don’t worry if you are unable to understand the solution, we will study about methods in detail later on.

Access this course and 1200+ top-rated courses and projects.