Stuck on Falsy Bouncer Challenge

Tell us what’s happening:

Hey guys.

I am stuck on this challenge for two days now. I tried adding isNaN(arr[i]) to the if condition but then that would mean it would evaluate a filled string to true.

The hint of the challenge is to convert these falsy values to Boolean. I managed to convert all the other falsy values except for NaN.

I looked at ‘Get Hint’ but that uses the .filter() method. Is there a way to pass the test with my current code?

Any help is appreciated, thank you!

Your code so far


function bouncer(arr) {
let newArr = [];
for (let i = 0; i < arr.length; i++) {
  console.log(`index is now ${i}, element is  ${arr[i]}`);
  if (arr[i] === "" || arr[i] === false || arr[i] === null || arr[i] === undefined || arr[i] === 0) {
    arr[i] = Boolean(arr[i]);
    
  }

  if (arr[i] != false) {
    newArr.push(arr[i]);
  }

}
return newArr;
}

// console.log(bouncer([false, null, 0, NaN, undefined, ""]));
// console.log(bouncer([null, NaN, 1, 2, undefined]));
// console.log(bouncer(["a", "b", "c"]));
// console.log(bouncer([7, "ate", "", false, 9]));




Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36.

Challenge: Falsy Bouncer

Link to the challenge:

I know sure what this if statement is doing?

You should need only one if statement in the solution.

I would not check if the array entry is equal to a special subset of the possible falsy values.

I would instead use the idea of truthy/falsy.

if (myVar) {
  console.log("this is truthy");
} else {
  console.log("this is falsy");
}