Bad test cases. Attention and fixes needed

Tell us what’s happening:
I am having an issue with two of the test cases which actually shouldn’t have to comply:

  1. dropElements([0, 1, 0, 1], function(n) {return n === 1;}) should return [1, 0, 1]
    If n===1, then 0 should not be returned, so here, my code crashes and cannot keep on advancing…

  2. dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;}) should return [3, 9, 2]
    If n>2, then 2 should not be returned, thus my code crashes since the test case says the opposite…

I attach here my code:

  **Your code so far**

function dropElements(arr, func) {
const 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.110 Safari/537.36

Challenge: Drop it

Link to the challenge:

You aren’t reading what the instructions are asking you to do. It isn’t asking you to filter the array

If n == 1, and the array is [0, 1, 0, 1], then first item is 0, not 1 so gets dropped, second item is 1, that is 1 so now return, that’s [1, 0, 1]

If n > 2, and the array is [1, 2, 3, 9, 2], then 3 is the first item > 2, so return [3, 9, 2]

2 Likes

ooouuuhhhh Jesus… Not about reding: I really misunderstood what it was asked (I am not english, nor is my first language)

I honestly apologize and I thank you for your response.

I really appreciate your work!

1 Like

I realise that makes it bit more difficult in that case! As it is, there are loads of learners who make the exact same mistake when it’s their first language, so you’re not alone in being a bit confused about the test cases

1 Like

Yeap, language barrier. Kind of embarrassing since I am not a rookie anymore :smiley:

Anyways, I am keeping of fire! (some exercises are really complex, almost like puzzles!)

Hope I can finish javascript soon!!

1 Like

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