← Back to challenges

Find NaN in an Array

JavaScriptHardarraysnumbers

Instructions

Create a function to find NaN in an array of numbers. The return value should be the index where NaN is found. If NaN is not found in the array, then return -1.

Examples

findNaN([1, 2, NaN]) ➞ 2

findNaN([NaN, 1, 2, 3, 4]) ➞ 0

findNaN([0, 1, 2, 3, 4]) ➞ -1

Notes

NaN will occur in the input array only once.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Temperature Conversion