This code is ok
function bouncer(arr) {
const filteredArr = [];
for (let i = 0; i < arr.length; i++) {
if (arr[i]) filteredArr.push(arr[i]);
}
return filteredArr;
}
console.log(bouncer([7, "ate", "", false, 9]));
console.log(bouncer([false, null, 0, NaN, undefined, ""]));
console.log(bouncer([null, NaN, 1, 2, undefined]));
Output:
[ 7, 'ate', 9 ]
[]
[ 1, 2 ]
But if this is
(arr[i]) filteredArr.push(arr[i])
replaced by it
if (arr[i] != false && arr[i] != null && arr[i] != NaN && arr[i] != "" && arr[i] != 0 && arr[i] != undefined) filteredArr.push(arr[i]);
i have this in output:
[ 7, 'ate', 9 ]
[ NaN ]
[ NaN, 1, 2 ]
I try to understand how this is work, but i can't.
p.s. sorry for my bad english.