Hello everyone.
I’m doing the this exercise, with the code i wrote, i almost pass it but apparently there are 2 test that wont work with this code.
below is the code that i wrote
function dropElements(arr, func) {
return arr.filter(func);
}
console.log(dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;}));
and the test that it didn’t fulfill are:
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]
when my code run, the first test would return [1,1]
instead of [1,0,1]
and with the second test, it would return [3,9]
instead of [3,9,2]
.
I don’t understand why the first test expecting [1,0,1]
because the function requirement is {return n === 1;}
and 0 is not equal to 1.
while for the second test why it expect [3,9,2]
when the function requirement is {return n > 2;}
. 2 is not bigger than 2, I’m not sure why it expect 2 to be included in the array.
please let me know what is my misunderstanding
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Drop it
Link to the challenge: