Falsy Bouncer -

Why NaN can’t be spliced?

function bouncer(arr) {
let arr1 = […arr]
for (let i = arr.length - 1; i >= 0; i–){
if (arr1[i] == false | arr[i] == ‘’ | arr1[i] == null | arr1[i] == NaN | arr1[i] == undefined) {
//console.log(arr[i])
arr1.splice(i, 1)
}
}
console.log(arr1)
return arr1;
}

bouncer([false, null, 0, NaN, undefined, “”]);

Link para o desafio:

You have a couple issues here.

First, what are you using the | symbol for? It is not the symbol you think it is.

Also, arr1[i] == NaN will always be false. You can not directly compare something with NaN to check to see if it is NaN. Do some research in how to detect if a value is NaN.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.