I am doing an exercise called, Falsy Bouncer in Basic Algorithm Scripting.
Here is my code:
function bouncer(arr) {
let res = [];
for(let i = 0; i < arr.length; i++){
if(arr[i] !== false && arr[i] !== null && arr[i] !== 0 && arr[i] !== "" && arr[i] !== undefined && arr[i] !== NaN){
res.push(arr[[i]]);
}
}
return res;
}
Error:
// running tests
bouncer([false, null, 0, NaN, undefined, ""]) should return [].
bouncer([null, NaN, 1, 2, undefined]) should return [1, 2].
// tests completed
I think my code is enough to fix this issue. But in reality, it’s not.
Please help me to figure out what’s going on?