Created
August 21, 2019 12:40
-
-
Save lionelB/3eafc5928a4cc4fc4d82fdc3767a0cce to your computer and use it in GitHub Desktop.
diff array of object
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
function diff(col1, col2, predicateFn = a => a) { | |
const contains = collection => value => | |
collection.find(item => predicateFn(item) === value); | |
const col1Contains = contains(col1); | |
const col2Contains = contains(col2); | |
return { | |
col1: col1.filter(item => !col2Contains(predicateFn(item))), | |
col2: col2.filter(item => !col1Contains(predicateFn(item))) | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment