← Back to challenges

Find the Largest Even Number

JavaScriptHardalgorithmsnumbersloopsrecursion

Instructions

Write a function that finds the largest number in an array nums that is also even. If there is no even number, return -1.

Examples

largestEven([3, 7, 2, 1, 7, 9, 10, 13]) ➞ 10

largestEven([1, 3, 5, 7]) ➞ -1

largestEven([0, 19, 18973623]) ➞ 0

Notes

Consider using the modulo % operator.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Sum of Digits of a Positive Integer