I’ve seen the answers and understand what to do. I am just curious why I wasn’t able to remove NaN from the new array(newArr) but I was able to remove all other falsy values. Thanks!
function bouncer(arr) {
let newArr = arr.slice();
let naughtyList = [false, null, 0, "", undefined, NaN];
for (let i = 0; i < newArr.length; i++) {
for (let j = 0; j < naughtyList.length; j++) {
if (newArr[i] == naughtyList[j]) {
newArr.splice(i, 1);
}
console.log(newArr);
}
}
return newArr;
}
bouncer([null, NaN, 1, 2, undefined]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36
Challenge: Basic Algorithm Scripting - Falsy Bouncer
Link to the challenge: