Implement an Element Skipper - Implement an Element Skipper

Tell us what’s happening:

Hello.

Tests 2, 3, 6 and 7 are failing.

I have tried different variations of this code and this makes the most sense to me so far. For test 2, the function is returning [2, 3, 4] which I don’t understand because 2 shouldn’t be returning true from the input func.

Your code so far

function dropElements(arr, func) {
  for (const item of arr) {
    if (func(item) == false) {
      arr.splice(arr.indexOf(item), 1);
    } else {
      return arr;
    }
  }
  return [];
}
console.log(dropElements([1, 2, 3, 4], function(n) {return n >= 3;}));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:155.0) Gecko/20100101 Firefox/155.0

Challenge Information:

Implement an Element Skipper - Implement an Element Skipper

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-element-skipper/a5deed1811a43193f9f1c841.md at main · freeCodeCamp/freeCodeCamp · GitHub

Hi @codingwookie,

If you add this log inside your loop, you’ll see that your code never “sees” the 2:

console.log(item,func(item))

Happy coding

Hi.

Your console line printed for 1 and 3 so why is the code not seeing the 2? I don’t see where it is being skipped.

the loop is iterating over the first item of the array, then it removes it. Now it iterates on the second item of the array, what is the second item of the array at this point? Is it the one you want to check?

Thanks for your reply. I read what you wrote, made a change and have passed all of the tests.