Tell us what’s happening:
I get it. This exercise couldn’t be this simple. The code I wrote runs through each iteration of the array and checks for a falsy value. But why is it not detecting NaN, undefined, and null as falsy?
If I compare them directly, IE if (null == false)
it returns the correct response. But in this if statement it doesn’t detect null, undefined, or NaN as false.
Your code so far
function bouncer(arr) {
var resultArr = []
for (let n = 0; n < arr.length; n++)
{
if ( arr[n] == true)
{
resultArr.push(arr[n])
console.log(resultArr)
}
}
return resultArr;
}
bouncer(["a", "b", "c"]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36
Challenge: Basic Algorithm Scripting - Falsy Bouncer
Link to the challenge: