Test logic doesn't make sense!

Tell us what’s happening:
Hello kind friends! I’ve tried my code two ways on the “Drop It” Javascript challenge, but I am failing the same two tests, whose logic doesn’t make sense to me. Can anyone explain why dropElements([0, 1, 0, 1], function(n) {return n === 1;}) should return [1, 0, 1] . and dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;}) should return [3, 9, 2] . ??? 0 does not === 1 and 9 is not > 2!!!

Your code so far


function dropElements(arr, func) {
 
 const dropt = arr.filter(func);
 console.log(dropt);
 
// var dropt = [];
 //for(var i = 0; i < arr.length; i++){
   //if (func(arr[i])){
     //dropt.push(arr[i]);
   //}
 //}
 //console.log(dropt);
 // Drop them elements.
 return dropt;
}

//dropElements([1, 2, 3], function(n) {return n < 3; });
//dropElements([1, 2, 3, 4], function(n) {return n >= 3;});
dropElements([0, 1, 0, 1], function(n) {return n === 1;});
//dropElements([1, 2, 3], function(n) {return n > 0;})
//dropElements([1, 2, 3, 4], function(n) {return n > 5;})
dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;}) 

Your browser information:

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

Challenge: Drop it

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/drop-it

Read the instructions very carefully. This challenge doesn’t ask for what most people expect it to. It is NOT supposed to remove all values that don’t return true.
(Also, 9 is definitely larger than 2.)

Thank you for your help! It always comes down to reading comprehension >x< also, i meant to say that 2 is not >2, in my rage i made a very comically stupid error!!!

A lot of people get on a roll and end up skimming the challenges because they think they know what to expect. Fast is slow. Slow is fast. :smiley:

2 Likes