Tell us what’s happening:
I came up with a code that works for every option but sometimes leaves a null element in the array. Could someone please look at the code and tell me why this is? (I know it can be done easier but I am more curious why it doesn’t work like this)
Thank you
Your code so far
function bouncer(arr) {
const arrLength = arr.length;
for (let i = 0; i <= arr.length; i++) {
if (Boolean(arr[i]) == false) {
arr.splice([i], 1);
i = 0;
}
}
console.log(arr);
return arr;
}
bouncer([null, null]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/falsy-bouncer/