I wrote the function to accomplish what was asked, but was wondering if there was a better and nicer way to do that?
function arrayDiff(a, b) {
let myArr = [];
for (let i = 0; i < a.length; i++) {
if (a[i] == b[0] || a[i] == b[1]) {
continue;
} else {
myArr.push(a[i]);
}
}
return myArr;
}
arrayDiff([1,2,3], [2,3]) //returns [1]
What if the length of the array "b" was more than just two elements, for example 5, how could I write a better code?