Nothing changes in the output no matter what I do

Tell us what’s happening:

Basically I’m trying to get it to display the result information. Instead it shows the entire array.
Not only that, it shows the index or number, but it never shows whats at the index of the item I’m looking for.

Your code so far

function destroyer(arr) {
var x = [];
x = arguments[0];
var y = [];
for(let a = 1; a <= arguments.length+1; a++){
  y= x.filter(thing => !x.includes(arguments[a]));

return arr;

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

Your browser information:

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

Challenge: Seek and Destroy

Link to the challenge:

So from what I coded - X is supposed to be the first argument. Y is supposed to hold everything that doesn’t match the other arguments.

x is definitely the first argument passed to the function, so you have that correct.

Based on the way you put the filter method line inside the for loop, you keep replacing the value of y each iteration of the for loop based on the same x (the array passed to the function). y will only contain different elements than x if the last argument passed to the function is not included in the x. You are using the filter method, but you do not use the argument (thing)? thing represents each element being iterated over in the filter method. Add the following console.log after the line with the filter method, to see how y changes during each iteration of the for loop.

  for (let a = 1; a <= arguments.length + 1; a++) {
    y = x.filter(thing => !x.includes(arguments[a]));

You might want to refresh your memory of how to use the filter method.

1 Like

Arigato! Thank you so much for helping me think through that! I succeeded at that assignment!

1 Like