I got the following solution for the Falsy, and it does return the proper responses, but it still shows a failing response. Don’t know why… can any body tell me please?
the challenge is to Remove all falsy values from an array.
Falsy values in JavaScript are false, null, 0, “”, undefined, and NaN.
Here is the code I came up with:
var cleanArr=[];
var notAccepted = [false, 0, “”, undefined, NaN];
var isFound = false;
function searchArray(srchStr, obj) {
for(var i=0; i<srchStr.length; i++) {
if (srchStr[i] == obj) return true;
}
}
function bouncer(arr) {
// Don’t show a false ID to this bouncer.
for (var i=0; i<arr.length+1; i++) {
if (searchArray(notAccepted, arr[i]) != true && arr[i] == arr[i]) {
// Since NaN is the only JavaScript value that is treated as unequal to itself, you can always test if a value is NaN by checking it for equality to itself:
cleanArr.push(arr[i]);
}
}
return cleanArr;
}
bouncer([1, null, NaN, 2, undefined]);