Seek and destroy parameters/arguments

Tell us what’s happening:

I just have a quick question about this problem. I’m a bit confused as to how you should go about solving the problem when the arguments aren’t defined as parameters going into the function. Or I think I’m confused what the difference between an argument and a parameter is. like the function we are writing looks like it only takes in an array so how do we account for the other arguments being passed in. any clarification would help!

Your code so far


function destroyer(arr) {
console.log(arguments)

return arr;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36.

Challenge: Seek and Destroy

Link to the challenge:

you may see that the arguments object contains all the passed in arguments, if you use it you can access the others

there are other ways to count for a variable number of arguments(ex. rest parameter), for this challenge you need to use the arguments object

ok thank you!

Can you see where I may be going wrong with my solution?

function destroyer(arr) {
  var targets = Array.from(arguments).slice(1)
  console.log(arr)
  arr.filter(function(num){
    return targets.indexOf(num) === -1
  })
  return arr;
}

you are not changing arr in any way, the filter method returns a new array

Hi!

My recommendations are:

use targets without slice(1) =>

let targets = [...arguments]

or:

let targets = Array.from(arguments);

Code the expected result as follows:

let result = arr.filter(num => !targets.includes(num));

after that:

return result;

There are also other solutions with the help of loops!

in that case targets[0] is the array, which is unnecessary to test against, and also wrong - it works because of how JavaScript is