Test Cases For Drop It


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; });

Please disregard, I re read the instructions and realized that we are not supposed to evaluate each item in the array, only until we find the first true case. Sorry for the needless forum post.

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.