Hello. I’m trying to complete the Seek and Destroy algorithm challenge. I’m trying to filter out any of the numbers passed as the second and third arguments.
Here is my code so far.
function destroyer(arr) {
let argArray = arguments[0];
let filteredArray = argArray.filter(x => x !== arguments[1] || x !== arguments[2]);
console.log(filteredArray);
return arr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
I was hoping this would create an array containing any numbers that don’t match the second and third arguments passed to destroyer(). But the filter method doesn’t work when it has the OR operator.
This works.
let filteredArray = argArray.filter(x => x !== arguments[1]);
But this doesn’t.
let filteredArray = argArray.filter(x => x !== arguments[1] || x !== arguments[2]);
Are you asking a question about the challenge? If so you will do better using the Ask for help button
If you are just sharing the answer it is preferred to not have answers around the forum, many people don’t like the spoilers, thank you for understanding - it is not even the answer to this challenge
The reason why (a || b) seems like OR in javascript is because inside the parenthesis is evaluated first.
(3 || 9) is (3) and when you use an if statement if (3){....} the 3 is coerced into a boolean, which is true.