findFirstEven

Easy · Functional Programming Concepts · 3 test cases

Given an array of numbers, find and return the first even number. If no even number is found, return undefined.

Examples

findFirstEven([1, 3, 5, 6, 7]) → 6
findFirstEven([1, 3, 5, 7]) → undefined

Starter code

function findFirstEven(arr) {

}

Complexity of the optimal solution

Time O(n), space O(1). The `find` method iterates through the array until it finds an element that satisfies the condition. In the worst case, it checks all 'n' elements. It does not create a new array, so space is constant.

Solve findFirstEven in the browser