Last active
September 20, 2022 14:04
-
-
Save brunos3d/e25427a3c5be42b39946c026ef042b8a to your computer and use it in GitHub Desktop.
arrayComplement and arrayIntersection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function arrayComplement<T, K1 extends keyof T>( | |
a: T[], | |
key: K1, | |
b: T[K1][] | |
) { | |
const setB = new Set(b.map((item) => item)); | |
return a.filter((item) => !setB.has(item[key])); | |
} | |
export function arrayIntersection<T, K1 extends keyof T>( | |
a: T[], | |
key: K1, | |
b: T[K1][] | |
) { | |
const setB = new Set(b.map((item) => item)); | |
return a.filter((item) => setB.has(item[key])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment