Basic Algorithm Scripting - Falsy Bouncer

I am currently going through the curriculum but shouldn’t the instructions be clearer? It said to remove values from the array but the solution given in the hint does not modify the input array.

Your code so far

function bouncer(arr) {
  for (let i = 0; i < arr.length; i++) {
    if (!Boolean(arr[i])) {
      arr.splice(i,1);
      i--;
    }
  }
  
  return arr;
}

bouncer([7, "ate", "", false, 9]);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0

Challenge: Basic Algorithm Scripting - Falsy Bouncer

Link to the challenge:

There are several ways to accomplish the task.

Fiddling with the loop iteration index inside of the loop is usually messy, so I prefer the approach of making a new array.

I get that there are several solutions but the solution provided is different from what the challenge is asking. This can be confusing later on. Since modifying an object is different from returning a new object.

I don’t see the instructions as mandating mutation, but

It is kind of confusing since the instructions says to remove values from an array and the solutions/hints does not show any omitting of values from an array. So, I think changing how the instruction are worded should clear the misunderstanding.

If you click on the link I posted, you will see that I suggested that change on our GitHub issue tracker…

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.