Hello,
I have a question regarding the “Drop It” challenge in Intermediate Algorithm section.
My code currently passes all test cases except two.
First: dropElements([0, 1, 0, 1], function(n) {return n === 1;}) should return [1, 0, 1].
Second: dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;}) should return [3, 9, 2].
My question is: how will n === 1 ever evaluate to true when n=0? This seems to be impossible to me. The same is true for n > 2 when n=2. The check is NOT for n >= 2, it is n > 2. Therefore, my code (see below) should work.
For some reason, if I copy and paste the basic solution in, all the tests pass. But how does “0 === 1” or “2 > 2” ever evaluate to true? Thank you for your help guys.
My Code:
function dropElements(arr, func) {
// Drop them elements.
var newArray = arr.filter(func);
return newArr;
}
dropElements([1, 2, 3], function(n) {return n < 3; });