Find NaN in an Array

Published by Deep Xavier in

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.

Watch a quick demo on how Edabit works.