I have an array array1 = [1,2,3,4,5,6] and another array array2 = [4,5].
The objective is to remove array2's elements from array1 with the least time complexity.
Final array is [1,2,3,6]
I know we can do something like this for every element
function remove(array, element) {
return array.filter(e => e !== element);
}
let array1 = [1,2,3,4,5,6];
array2 = [4,5];
array2.forEach(el => {
array1 = remove(array1, el);
});
How do i make it better?