The challenge is https://www.freecodecamp.org/challenges/falsy-bouncer
Can someone please explain what’s wrong with my code?
function bouncer(arr) {
var newArray = arr.filter(function(element){
return element != Boolean();
});
return newArray;
}
bouncer([7, "ate", "", false, 9, null, false, 0, NaN, undefined]);
It works but it only works for “false” and “0”. I understand that I am overcomplicating myself by doing this when I can simply just use the code below.
function bouncer(arr) {
var newArray = arr.filter(Boolean);
return newArray;
}
However, I am interested in finding what’s the problem.
Thanks in advance!