Click4Ai

13.

Easy

Write a function filter_even(arr) that returns a new list containing only the even numbers from the input array.

Example:

Input: arr = [1, 2, 3, 4, 5, 6, 7, 8]

Output: [2, 4, 6, 8]

Constraints:

  • Array length: 0 <= len(arr) <= 1000
  • An even number is divisible by 2 (num % 2 == 0)
  • Return an empty list if no even numbers found
  • Test Cases

    Test Case 1
    Input: [1, 2, 3, 4, 5, 6, 7, 8]
    Expected: [2, 4, 6, 8]
    Test Case 2
    Input: [1, 3, 5, 7]
    Expected: []
    Test Case 3
    Input: [2, 4, 6]
    Expected: [2, 4, 6]
    + 2 hidden test cases