So i am practicing algorithms(javascript), and i come across this challenge, where we have to filter an array, remove the following elements:
false, NaN, undefined, "", null, 0
My code seems to have problems with strings and chars, it failed these tests.
-bouncer([7, "ate", "", false, 9]) should return [7, "ate", 9] (returned [7, 9])
-bouncer(["a", "b", "c"]) should return ["a", "b", "c"] (returned [])
function bouncer(arr) {
return arr.filter(function(element)
{
if (element != false && !isNaN(element) && element != null && element != "" && element != undefined)
{return element;}
}
);
}
I would love a simple explanation of the concept i am missing