I have been attempting to remove the common elements from the input arguments and generate a final array with only unique elements. In the provided example, my expected final array is [1,4,5], but instead I am getting [1,3,4,5]. Upon debugging, it seems that one of the elements (3) is not being processed in the loop. After element (2), the code appears to skip straight to element (4). This behavior has left me confused - could there be an issue with my code? Any assistance on this matter would be greatly appreciated. Thank you.
function arrayBreaker(arr) {
let test = [];
test.push(arguments[1]);
test.push(arguments[2]);
let target = arguments[0];
target.filter(val => {
if (test.indexOf(val) > -1) {
target.splice(target.indexOf(val), 1);
}
});
return target;
}
console.log(arrayBreaker([1,2,3,4,5], 2, 3));