https://www.greatfrontend.com/questions/javascript/intersection-with
The intersectionWith function takes a custom comparator function and multiple arrays as arguments. It compares the elements of the arrays using the comparator function to determine equality. The function returns a new array containing the elements that are present in all given arrays.
intersectionWith(comparator, ...arrays);
comparator(Function): The comparator function used to determine equality between elements. The function will be invoked with two arguments (arrVal, othVal) representing the two elements being compared. It should return true if the elements are considered equal, and false otherwise.arrays(...Array): The arrays to inspect.
(Array): Returns the new array of chunks.
const arr1 = [
{ x: 1, y: 2 },
{ x: 2, y: 3 },
];
const arr2 = [
{ y: 2, x: 1 },
{ x: 3, y: 4 },
];
const result = intersectionWith(
(a, b) => a.x === b.x && a.y === b.y,
arr1,
arr2,
); // => [{ x: 1, y: 2 }]