function destroyer(arr){
let len = arguments.length;
let arry = [];
for(let i = 1;i< len;i++){
arry.push(arguments[i])
}
for(let x =0;x<arr.length;x++){
for(let j=0;j<arry.length;j++){
if(arr[x] == arry[j]){
arr.splice(arr.indexOf(arry[j]),1);
}
}
}
console.log(arr);
};
So, this function takes an array followed by some extra arguments. This function delete items in this array which has some value of those extra arguments.
destroyer([3, 5, 1, 2, 2], 2, 3, 5);
result is [1,2];
this function should delete all 2,3,5 in this array . But I don’t know why it didn’t delete last 2 . Please someone help me is there anything I am missing?