Hi. I am have attempted the falsy Bouncer, but I have a hard time dealing with the falsy NaN. I have tried to use isNaN and other options but still nothing. Please can someone help me with this very beginner solution.
Can it be fixed?
function bouncer(arr) {
// Don't show a false ID to this bouncer.
var falsyValues = [false, null, 0, "", undefined, NaN];
var array =[];
array = arr.filter(function (value){
// for (var i = 0; i < falsyValues.length; i++){
if(value === false && value !== "" && value !== null && value !== 0 && value !== undefined ){
return arr;
}
// }
});
return array;
}
isNaN doesn’t work as you would expect. It allows coercion, so if you passed it, say, 'hello', it will coerce it to a number and come up with NaN, so it returns true.
There’s a stricter Number.isNaN function that only works with numbers and returns true just for actual NaN values.