Hi, I need help with this challenge. I don´t understand why when i test this code doesn´t remove the values null
, NaN
y ""
. I think it might be because of the splice()
that I’m using it wrong.
function bouncer(arr) {
for (let i = 0; i < arr.length; i++) {
switch (arr[i]) {
case false:
case null:
case undefined:
case 0:
case "":
case NaN:
arr.splice(i,1);
//break;
}
}
console.log(arr);
return arr;
}
bouncer([false, null, 0, NaN, undefined, ""]);
Challenge: Falsy Bouncer
Link to the challenge: