Tell us what’s happening:
Someone explain me these two test cases. Why 0 is returned when n===1? and why 2 is returned when n > 2. Thanks in advance
dropElements([0, 1, 0, 1], function(n) {return n === 1;})
should return [1, 0, 1]
dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;})
should return [3, 9, 2]
Your code so far
function dropElements(arr, func) {
// Drop them elements.
var arr1 = [];;
for(var i = 0; i < arr.length; i++) {
if(func(arr[i]) === true) {
arr1.push(arr[i]);
}
}
console.log(arr1);
return arr1;
}
dropElements([0, 1, 0, 1], function(n) {return n === 1; });
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0
.
Link to the challenge: