I tried solving this through a filter function that would iterate over a list of the “falsy” arguments and return false or true depending on if the array value matched any of the words.
Edit: Disclaimer, I solved it later using the correct way. Just curious why this doesn’t work.
function bouncer(arr) {
return arr.filter(function falsy(toFilter) {
var testVal = [false, null, 0, NaN, undefined, ""];
for (i = 0; i < testVal.length; i++){
if (toFilter === testVal[i]){
return false;
}
}
return true;
});
}
It worked for the first two tests but
bouncer([false, null, 0, NaN, undefined, ""]);
returned [null]
and
bouncer([1, null, NaN, 2, undefined])
returned [1, null, 2]
why is this?