Seek and destroy (Feedback)

I just ran the tests and everything is ok. Can you guys tell me if this is a good solution?
I just want to know if I’m on the right path. Thanks

  Since arr is an expected argument and it's always available (in our case), I deleted it from the arguments object
  That way, I can freely use the remaining object to create a new set

function destroyer(arr) {
  delete arguments[0]
  var args = new Set(Object.values(arguments))
  var newArr = []
  for (let i = 0; i < arr.length; i++){
    if (args.has(arr[i]) === false) {
  return newArr

destroyer([1, 2, 3, 1, 2, 3], 2, 3); // [1, 1]
destroyer([1, 2, 3, 5, 1, 2, 3], 2, 3) // [1, 5, 1]
destroyer([3, 5, 1, 2, 2], 2, 3, 5) // [1]
destroyer([2, 3, 2, 3], 2, 3) // []
destroyer(["tree", "hamburger", 53], 'tree', 53) // ["hamburger"]
destroyer(["possum", "trollo", 12, "safari", "hotdog", 92, 65, "grandma", "bugati", "trojan", "yacht"], "yacht", "possum", "trollo", "safari", "hotdog", "grandma", "bugati", "trojan") // [12,92,65]

Your solution runs what matters and your code readable - clean , /o/
I didn’t know this Set, I don’t think I saw it in the freeCodeCamp challenges.
My solution would be:

function destroy(arr, ...arr1){
      let newArr = arr.filter(data => arr1.includes(data) != true); 
     return novo;

Implementing parameters rest and filter.

Saw some of the other solutions after managing to get my code working, and one of the things I was trying to avoid was a nested loop. Deleted my code a few times and then decided to play around with the Set object, since it looked way more easier than the other possible solutions that had come to my mind.
My goal when approaching those algorithms is to just finish them without asking for help. First, I just want to code something that works, and then I can start thinking about why that code is bad or good. I also totally forgot that I can do something like delete array[0] and I was like “JavaScript sucks”. After all, those challenges make you feel the importance of knowing how to deal with certain kind of data structures…
Anyway, thanks for you reply. I should definetly play more with that filter method. It looks so powerful.

1 Like