Hello, I need some help with my code. It currently filters an input array to remove any values that match specific arguments. However, I am struggling to iterate through all the arguments effectively. Here is the code that is currently working:
function destroyer(arr) {
var arg2 = arguments[1];
var arg3 = arguments[2];
var arg4 = arguments[3];
var result = arr.filter(function(arg) {
if (arg != arg2 && arg != arg3 && arg != arg4) {
return (arg);
}
});
return result;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
I attempted to iterate through all arguments using a for loop, but it's not working as expected. I'm having difficulty understanding what exactly is being passed through the callback function in the arr.filter method. Here is the code snippet:
function destroyer(arr) {
var result = arr.filter(function(arg) {
for (var i = 1; i < arguments.length; i++) {
if (arg != arguments[i]) {
return (arg);
}
}
});
return result;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Am I close to the correct approach or completely off track with my code? Any guidance is appreciated.