Faulty logic for tests

Tell us what’s happening:

Two tests do not pass:

  1. dropElements([0, 1, 0, 1], function(n) {return n === 1;}) should return [1, 0, 1] .
    My code returns [1, 1], which makes sense.
    Returning [1, 0, 1] does not. 0!===1

  2. dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;}) should return [3, 9, 2] .
    My code returns [3, 9], which makes sense.
    Returning [3, 9, 2] does not. 2!>2

    Your code so far


function dropElements(arr, func) {
let result = arr.filter(func);
console.log(result);
return result;
}

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

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36

Challenge: Drop it

Link to the challenge:

Careful, a filter won’t work here

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.

Until is a key word here. Strip off elements before the first passing element, but not after.

Hi JeremyLT, thanks for that.
Highlighting the until, makes all the difference to how the problem is posed.

1 Like