Algorithm Seek and Destroy

🚩 Remember to use Read-Search-Ask if you get stuck. Try to pair program πŸ‘₯ and write your own code πŸ“

🏁 Problem Explanation:

This problem is a bit tricky because you have to familiarize yourself with Arguments, as you will have to work with two or more but on the script you only see two. Many people hardcode this program for three arguments. You will remove any number from the first argument that is the same as any other other arguments.

Relevant Links

πŸ’¬ Hint: 1

You need to work with arguments as if it was a regular array. The best way is to convert it into one.

try to solve the problem now

πŸ’¬ Hint: 2

You need to filter, this also means you need to create a callback function, one that checks if the element is on the indexOf()

try to solve the problem now

πŸ’¬ Hint: 3

To convert arguments into an array use this code var args =;

try to solve the problem now

Spoiler Alert!


Solution ahead!

πŸ”° Basic Code Solution:

function destroyer(arr) {
  var args =;
  args.splice(0, 1);
  return arr.filter(function(element) {
    return args.indexOf(element) === -1;

πŸš€ Run Code

Code Explanation:

  • The first line will turn the arguments variable into a full array instead of the limited array it currently is.
  • Next I remove the first argument since I don’t need, since I only want the other arguments passed besides the first which is the array we are going to compare against.
  • Then use the filter() to filter out the elements that are on the array and keep the ones that are not.

Relevant Links

πŸ† Credits:

If you found this page useful, you may say thanks to the contributors by copying and pasting the following line in the main chat:

Thanks @Rafase282 for your help with Algorithm: Seek and Destroy


  • ⚠ DO NOT add solutions that are similar to any existing solutions. If you think it is similar but better, then try to merge (or replace) the existing similar solution.
  • Add an explanation of your solution.
  • Categorize the solution in one of the following categories β€” Basic, Intermediate and Advanced. πŸš₯
  • Please add your username only if you have added any relevant main contents. (⚠ DO NOT remove any existing usernames)

See πŸ‘‰ Wiki Challenge Solution Template for reference.