Need help Seek and Destroy

Tell us what’s happening:

Your code so far

function destroyer(arr) {
  let arrNew=[];

  // Remove all the values
  for(let i=0;i<arguments.length;i++){
  return arrNew.slice(0,1).filter( function(i) { return !arrNew.slice(1).includes(i) } );

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

Your browser information:

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

Link to the challenge:

return arrNew.slice(0,1).filter( function(i) { return !arrNew.slice(1).includes(i) } );

Please describe, what you think this line does.

You have the right idea but I think your code became confusing with all the indexing and calls to slice. I believe if you log to console arrNew.slice(0,1) you will see why it is not working.

arrNew.slice(0,1) // returns a nested array [ [ 1, 2, 3, 1, 2, 3 ] ]
  //with only one array element

so below is not filtering what you think


Why not just call it arr as passed in the function arg list? That change alone would pass your code.


I would suggest…

  1. Only a slight change to your code to isolate the additional arguments into their own named array (which I named others here)
  2. Refer to the passed array as arr as named in the arguments list of function instead of slicing it from the arguments
function destroyer(arr) {
  let others =[];

  // isolate additional arguments
  // note i initialized to 1 to skip arr
  for(let i=1;i<arguments.length;i++){
  // now others is [2,3]

  return arr.filter( function(i) { return !others.includes(i) });

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

There are other ways to capture the additional arguments in an array but this was most like your original code.

1 Like