function bouncer(arr) {
// Don't show a false ID to this bouncer.
for(let i=0;i<arr.length;i++){
console.log(arr[i])
if(!arr[i]){
arr.splice(i,1);
i=0}
}
if(arr[0]==null) arr.splice(0,1); //this solved my problem. Somehow the null wasn't being removed so remove explicitly. this will help to solve your problem
console.log(arr)
return arr;
}
bouncer([7, "ate", "", false, 9]);
bouncer([false, null, 0, NaN, undefined, ""])
Thanks for your reply I could have used a very simple solution like. But I want to do it with a for loop that’s my challenge. Thanks for pointing out the flaw. I’ll make another one.
function bouncer(arr) {
// Don't show a false ID to this bouncer.
let newArr=arr.filter((x)=>x==true)
console.log(newArr)
return newArr
}