Hi everybody!
My code for solving the “Falsy Bouncer” challenge works but I’m actually not sure how…
One of the requirements for the challenge is that the function will filter the “NaN” items from the array, and I didn’t do anything about it and it still works. Does anyone know how and why?
Here is the challenge:
Remove all falsy values from an array.
Falsy values in JavaScript are false, null, 0, “”, undefined, and NaN.
And here is my code:
function filtered(value) {
if((value !== null) && (value !=="") && (value !== 0) && (value !== false) && (value !== undefined)) {
return value;
}
}
function bouncer(arr) {
var newArr;
newArr = arr.filter(filtered);
return newArr;
}
bouncer([1, null, NaN, 2, undefined]);
Thanks!
Vered
