Implement intersectionBy, differenceBy, unionBy
The three classic set operations, generalized to work on arrays of objects by comparing a key derived from each item via keyFn (not the objects themselves, two different objects can represent "the same" item).
intersectionBy(arr1, arr2, keyFn), items inarr1whose key also appears inarr2.differenceBy(arr1, arr2, keyFn), items inarr1whose key does not appear inarr2.unionBy(arr1, arr2, keyFn), all items from both, deduplicated by key (first occurrence wins), in order.
const a = [{ id: 1 }, { id: 2 }];
const b = [{ id: 2 }, { id: 3 }];
intersectionBy(a, b, (x) => x.id); // [{ id: 2 }]
differenceBy(a, b, (x) => x.id); // [{ id: 1 }]
unionBy(a, b, (x) => x.id); // [{ id: 1 }, { id: 2 }, { id: 3 }]