UNPKG

@cycxllin/cmpt315-a2

Version:

Fulfills CMPT 315 Assignment 2, MacEwan University Winter 2024.

30 lines (24 loc) 768 B
/* Find all the indexes where NaN is found in a given array of numbers and NaN. Assumption: non-NaN types in an array are not NaN; ie. we are looking for the number-NaN type specifically, not NaN=not a number Parameters: array Returns: array of numbers indicating indicies where NaN is present, empty array if no NaN present, -1 if error occurs */ function findNaNIndex(arr){ if (Array.isArray(arr)){ let indicies = []; arr.forEach( (element, index) => { if (Number.isNaN(element)){ indicies.push(index); } }); return indicies; } else { console.error("Error: Parameter passed is not an array"); return -1; } } module.exports = findNaNIndex;