Basic Algorithm Scripting - Seek and Destroy

Hey guys, I think I’m stuck here and I really need some help.

I came up with the following Code:
(I’m pretty sure there is a much simpler way to solve this than mine, but I wanted to try it myself before looking into the wiki.)

`function destroyer(arr) {

return arr.filter(function(a){
var matched = 0;

for (var i = 1; i < destroyer.arguments.length; i++){
  if (a == destroyer.arguments[i]) {
    matched++;
  }
}

if (matched === 0) {
  return true;
}

return false;

});

}

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

In my opinion it works just fine.
The code removes all elements from the initial array that are of the same as the given arguments.

Here is the repl.it-Link: Sign up to continue coding - Replit

The FCC Console is always showing me : TypeError: Type Error

I hope someone knows an answer how I am able to pass the Challenge or how to get my Code to work.

This is my solution, it looks different from yours:

In your code, I stored the destroyer function’s arguments in a variable, then used that in the inner function instead.

var destroyerArgs = Array.from(arguments);

// ...

for (var i = 1; i < destroyerArgs.length; i++)

// ...

I think I’ve read somewhere that referencing arguments via its function’s name is not a good idea.

1 Like

Thank you @kevcomedia, putting the arguments in an Array made my Code work :slight_smile: