Seek and Destroy Difficulty


Hi, could anyone take a couple minutes to explain why this doesn’t work? (Goal: Remove elements in initial array that are same value as subsequent arguments.)

function destroyer(arr) {

 var args =;

   return args.filter(function(s){

       return args[0][s].indexOf(args[1]) < -1;

 destroyer([1, 2, 3, 1, 2, 3], 2, 3);

Train of thought: Turn argument functions into an array. Filter through first array element. Return each element within first array that is false for second element. One it’s working I’ll pop in a for loop to check the rest of the elements.
Type error: Cannot read property ‘indexof’ of undefined. Really quite stumped by this.

Thanks in advance.


the error says you are accessing indexOf as a property of an undefined value - since the expression here is args[0][s].indexOf it means args[0][s] is undefined - you can try to see why this is by adding a console.log to the filter callback