Asymmetrical Array Diff
Easy method to get the asymmetrical difference (elements in the first array but no the second) of two arrays.
Returns the elements of a
that don’t exist in b
(asymmetrical/left diff).
export function asymmetricalDiff<T>(a: Array<T>, b: Array<T>) {
return a.filter((item) => !b.includes(item));
}
Usage
const a = ["🐍", "🖥", "🎋", "🏌"];
const b = ["🐩", "🖥", "🚒", "🏌"];
asymmetricalDiff(a, b); // ["🐍", "🎋"]
asymmetricalDiff(b, a); // ["🐩", "🚒"]