This code is similar to the previous exercise, Diff Two Arrays.
I start by destructuring the argument into arr using the ... spread operator and repeat that process for another destructured component I named destroy.
Next I filter the array arr by the elements in the destroy array and return only those unique values.
//SUGGESTED CODE 2
function destroyer(arr) {
let args = Array.from(arguments).slice(1);
return arr.filter(val => !args.includes(val));
}
If arguments is really a necessary component of this exercise (it isn’t tested for), then this uses that solution.
Like Solution 2, it takes the elements you’re looking to destroy (everything after the array) and assigns those values to the new variable, args.
Then just like I did in suggestion 1, filter arr using args and return all unique values.
I’ve done that a few times and after I was mistaken about the error they instructed me to create a post in the forum. Regardless, we both see a problem with the code so I’m sure it will be taken up.
@alaa-essaies, @anik-io, @tomstor82
You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.
I always thought sharing was caring?! It is helpful to see solutions in my opinion, and especially shorter and easier ones. My post implies replies from whomever has suggestions, but I’ll make a note of your comment.