Tell us what’s happening:
Hello kind friends! I’ve tried my code two ways on the “Drop It” Javascript challenge, but I am failing the same two tests, whose logic doesn’t make sense to me. Can anyone explain why 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]
. ??? 0 does not === 1 and 9 is not > 2!!!
Your code so far
function dropElements(arr, func) {
const dropt = arr.filter(func);
console.log(dropt);
// var dropt = [];
//for(var i = 0; i < arr.length; i++){
//if (func(arr[i])){
//dropt.push(arr[i]);
//}
//}
//console.log(dropt);
// Drop them elements.
return dropt;
}
//dropElements([1, 2, 3], function(n) {return n < 3; });
//dropElements([1, 2, 3, 4], function(n) {return n >= 3;});
dropElements([0, 1, 0, 1], function(n) {return n === 1;});
//dropElements([1, 2, 3], function(n) {return n > 0;})
//dropElements([1, 2, 3, 4], function(n) {return n > 5;})
dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;})
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
.
Challenge: Drop it
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/drop-it