I wrote this code to remove all 2
and 3
from the array and wanted to have this result:
destroyer([1, 2, 3, 1, 2, 3], 2, 3); // returns [1, 1]
but instead the result is:
destroyer([1, 2, 3, 1, 2, 3], 2, 3); // returns [1, 2, 1, 3]
This is function code:
function destroyer(arr) {
var a = Array.prototype.slice.call(arguments);
var b = a[0];
for (var i = 1; i < a.length; i++) {
if (b.indexOf(a[i]) !== -1) {
b.splice(a[i], 1);
}
}
return b;
}
console.log(destroyer([1, 2, 3, 1, 2, 3], 2, 3));