Why is the NaN case not working?

All of the cases work with the exception of the NaN case. Why can’t I get it to work?

function bouncer(arr) {
let newArray = […arr];// creating a new Array and setting it equal to arr to prevent mutating arr.
let newNewArray = ; // creating the final array

for(let i=0;i<newArray.length;i++){

switch(newArray[i]){ //switch statement to cover every case. 
  case false:
  break;
  case null:
  break;
  case 0:
  break;
  case NaN: //Why is this not working?
  break;
  case undefined:
  break;
  case "":
  break;
  default:
  newNewArray.push(newArray[i])
  break;


}

}

console.log(newNewArray); //testing again
return newNewArray;

}

bouncer([7, “ate”, “”, false, 9]);
bouncer([“a”, “b”, “c”])
bouncer([false, null, 0, NaN, undefined, “”])
console.clear;

One of the oddities of NaN is that it is never equal to itself. In other words:

NaN === NaN // false

Yeah, it’s a little weird.

But that’s OK. If you’re working on the one I’m thinking about, you don’t actually need a switch. Hint: Look up the word “falsy”.

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