Why wont this work?

Why wont this work?
0.0 0

#1

function destroyer(arr) {
var args = Array.prototype.slice.call(arguments); //turns arguments into arrays

function checkArgs() {
    for (var i = 0; i < arr.length; i++) {
        for (var j = 0; j < args.length; j++) {
            if (arr[i] == args[j]) {
                delete arr[i];
            }
        }
    }
}


return arr.filter(checkArgs);

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);// remove 2nd, 3rd, etc. arguments from first argument… and return 1st argument (arr).


#2

You seem to not understand what the filter callback function (in your case checkArgs) expects for arguments. I suggest reading about the filter function’s callback arguments before proceeding. If you have any specific questions about how to use the callback function, then ask here.

The filter function will iterate through the array on which it is called and execute the callback function for each element. You use the callback function’s arguments (which you did not specify in your checkArgs function) to create logic to return back a true or false value. Any iteration which results in a truthy value being returned, gets included in the final array created. There is no need to use the outer for loop (seen below), because the filter does this automatically:

for (var i = 0; i < arr.length; i++) {
  .  
  // code goes here 
  .
}

#3

Thank you so much for explaining I don’t need the for loop. It makes much more sense now. Thanks for your time!!