Seek and Destroy Challenge Solution

Tell us what’s happening:
Describe your issue in detail here.
Hello!

My “Seek and Destroy” challenge solution passed all the tests but was different from the solutions in the explanations.

Looking for some feedback on the solution I came to. Is it just as good? Any awkward/wonky code?

For instance, one of the other solutions builds the “items to remove” array using

Object.values(arguments).slice(1);

I like this better than what I came up with.

  **Your code so far**

function destroyer(arr) {
let newArr = arguments[0];
let darr = [];
for (let i=1; i < arguments.length; i++ ) {
  darr.push(arguments[i])
};
let finalArr = newArr.filter(  num => !darr.includes(num))

return finalArr;
}

destroyer(["tree", "hamburger", 53], "tree", 53)
destroyer([1, 2, 3, 1, 2, 3], 2, 3);

// if element x is in newArr, remove it from newArr
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36

Challenge: Seek and Destroy

Link to the challenge:

Why go through all the bother of making all of these arrays when these arrays already exist?

Thanks for the reply. I take it I don’t need to create the arrays then? Could I just use
“arguments[0]” in place of the newArr?

Will try when I get home.

Thanks again!

You can even get slick with this:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/use-the-rest-parameter-with-function-parameters

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.