Algorithm challenges: Falsy Bouncer

Tell us what’s happening:

Hi, I got stuck at one of the Algorithm Scripting challenges. It seems I chose a complicated way, because I wanted to iterate through an array with a loop and check whether neither of those has falsy values

Could you please advise me whether it will work or I should choose something else instead
Thank you in advance!

Your code so far


function bouncer(arr) {
  // Don't show a false ID to this bouncer.

for (let i = 0; i < arr.length; i++) { 
 arr.filter(function() {arr[i] !== undefined || arr[i] !==null || arr[i] !==NaN || arr[i]!==0 || arr[i]!=="" || arr[i] !== false});
}

 return arr;
}
bouncer([7, "ate", "", false, 9]);

Your browser information:

Chrome Version 75.0.3770.100 (Official Build) (64-bit)

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/falsy-bouncer

You absolutely don’t need the loop as the filter method already check each item in the array. But the callback need a parameter to use.

You can use a loop if you want, but not together with filter. Maybe push the values you want to keep to an empty array and then return that array? (If you are not confident with filter)


There is a thing you should know about a few of these data types. For example NaN !== NaN is always true.

Instead you should be using the property of these falsy values, that when evaluated as a Boolean they evaluate as false.
This could be interesting for you:

Thank you very much!