Tell us what’s happening:
for the given test statement; it is clear that the index 4 of value false
is skipped for no known reason.
Your code so far
function bouncer(arr) {
for (const ind in arr) {
console.log(`!arr[${ind}]: ${!arr[ind]} of value: ${arr[ind]}`);
if (!arr[ind]) {
arr.splice(ind, 1);
}
}
console.log("arr: " + arr);
return arr;
}
bouncer([7, "ate", "", false, 9]);
Output
!arr[0]: false of value: 7
!arr[1]: false of value: ate
!arr[2]: true of value:
!arr[3]: false of value: 9
arr: 7,ate,false,9
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36
.
Challenge: Falsy Bouncer
Link to the challenge: