I can’t imagine that my code is far off, but my results show no success in terms of the test check marks. I am hoping that I am off by a little bit. Can anyone see if I am close?
**Your code so far**
function destroyer(arr) {
let length=arr.length;
for (let i=1; i<length; i++) {
let length0=arr[0].length;
let clips=0;
if (length0>0) {
for (let j=0; j<length0; j++) {
if (arr[0][j-clips]==arr[i]) {
arr[0].splice(j-clips, 1);
clips++;
}
}
}
}
return arr[0];
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Seek and Destroy
You are removing items as you iterate through the array. That creates difficult to diagnose bugs. I recommend you not do that. I would instead make a brand new output array.
I suggest you to use this logging somewhere in the function:
console.log(arguments)
That should give you some ideas about approach or further research.
In my solution I used combination of methods: filter(), includes() and slice().
But it’s not a big deal - if you’ll understand structure of arguments object - you will be able to implement bunch of different solutions for this task.
So the first battle is to properly import the destroyer function and all the arguments. In some cases it a an array of numbers with an unknown number (2 or 3) of number arguments. However, in some cases the destroyer function array is a mix of strings and numbers and the unknown number of arguments is also strings and numbers. I am going to try some things. Maybe the spread thingy will work here.