The second and the last test case is wrong in this because n===1 cannot include 0 in array and n>2 cannot include 2 in array

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

function dropElements(arr, func) {
console.log(arr.filter((item) => func(item)))
return arr.filter((item) => func(item))

}

dropElements([1, 2, 3], function(n) {return n < 3; });
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36

Challenge: Drop it

Link to the challenge:

You’re misunderstanding the instructions. They say:

Given the array arr , iterate through and remove each element starting from the first element (the 0 index) until the function func returns true when the iterated element is passed through it.

What you’re missing is "until the function func returns true ". In other words, once you encounter something that returns true, stop removing items.

The test cases are fine. Thes problem has been done by tens of thousands of people.

Oh I am sorry, I just realised it . Thank you for clearing it out!

1 Like

That’s cool. Part of being a developer is getting good at reading specs very closely.

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