Intermediate Algorithm Scripting: Seek and Destroy

Intermediate Algorithm Scripting: Seek and Destroy
0

#1

This is my code witch doesn’t for some reason:
function destroyer(arr) {
let test = Array.from(arguments[0]);
let args = Array.from(arguments).slice(1);
return test.filter(function(cur) {
return !args.includes(cur);
}

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

On the other hand this correct solution:
function destroyer(arr) {
var args = Array.from(arguments).slice(1);
return arr.filter(function(val) {
return !args.includes(val);
});
}
I would like to know why my code doesn’t work.Am I doing something wrong with arguments?


#2

Well, you have syntax errors.

return test.filter(function(cur) {
    return !args.includes(cur);
}
// missing ) for filter()
// missing } to close destroyer()

#5

I’m still worried if I did an appropriate procedure for this example. But the code was accepted.

First I changed the function header so it has the arguments (beside the array) defined.
then I used a function mentioned in the challenge before this one.
The past exercise compared a couple of arrays and produced a new array with the differences. SO this exercise has only to deliver the surviving elements of the filtered array.

```
function destroyer(arr, …arg) {
return arr.filter(elem => arg.indexOf(elem) === -1);
}