Tell us what’s happening:
Can anyone tell me why my code is wrong?
I really dont get why and how
dropElements([0, 1, 0, 1], function(n) {return n === 1;})
should return [1, 0, 1] ? How can 0 be strictly equal to 1?
dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;})
how can it return [3, 9, 2] ? 2 is not greater than 2 ![]()
Your code so far
function dropElements(arr, func) {
const filteredElems = [];
for (let i = 0; i < arr.length; i++) {
const currentItem = arr[i];
if (func(currentItem)) filteredElems.push(currentItem);
}
return filteredElems;
}
dropElements([1, 2, 3], function(n) {return n < 3; });
Your browser information:
User Agent is: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Mobile Safari/537.36
Challenge: Intermediate Algorithm Scripting - Drop it
Link to the challenge: