# Seek and Destroy need help with my logic

Tell us what’s happening:

Can somebody help how to solve this task. I went over it several times and I cannot find my logical mistake. A hint would be great. Thanks

``````function destroyer(arr) {
// Remove all the values
var result = arr.filter(newArr);

function newArr(val) {
for (var i = 1; i < arguments.length; i++) {
for (var j = 0; j < arr.length; j++) {
if(arguments[i] !== arr[j]) {
return val;
}
}
}
}

return result;
}

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

Your Browser User Agent is: `Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0`.

https://www.freecodecamp.org/challenges/seek-and-destroy

Look at what’s inside arguments:

``````function destroyer(arr) {
console.log(arguments)
// Remove all the values
var result = arr.filter(newArr);

function newArr(val) {
console.log(arguments)
for (var i = 1; i < arguments.length; i++) {
for (var j = 0; j < arr.length; j++) {
if(arguments[i] !== arr[j]) {
return val;
}
}
}
}

return result;
}

console.log(destroyer([1, 2, 3, 1, 2, 3], 2, 3));
``````

Arguments are what’s passed into the function. You’re working with two functions. Each function has its own arguments object.

The following is mine, there are simmilar way of thinking but different way of code

``````function destroyer(arr){
//convert arguments into array

var args = Array.from(arguments);

//comparing the indexes of array and arguments
//and delete if it's equal
for(var i in arr){
for(var j in args){
if(arr[i] === args[j]){
delete arr[i];
}
}
}
// the expected result of arr would contain some null values
//therefore, we need to filter() those null
return arr.filter(arr => Boolean(arr));
}

``````

Instead of just posting your solution (which the OP may not want to see just yet), try giving him hints what is currently causing his current solution to not pass the challenge.

Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, if you post a full passing solution to a challenge, please surround it with `[spoiler]` and `[/spoiler]` tags on the line above and below your solution code.

Thank you.

1 Like