Last active
June 6, 2023 15:49
-
-
Save ernestlv/f4ef8513ffc962ab60c30aa67ebd82b0 to your computer and use it in GitHub Desktop.
Calculate the difference between two sets
This file contains 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
/* it is in A but not in B */ | |
function diff(arrA, arrB) { | |
const mapB = arrB.reduce((res, b) => ({ ...res, [b.key]:b }), {}); | |
return arrA.reduce((res, a) => !(a.key in mapB) ? [ ...res, a ] : res, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment