Skip to content

Instantly share code, notes, and snippets.

@lionelB
Created August 21, 2019 12:40
Show Gist options
  • Save lionelB/3eafc5928a4cc4fc4d82fdc3767a0cce to your computer and use it in GitHub Desktop.
Save lionelB/3eafc5928a4cc4fc4d82fdc3767a0cce to your computer and use it in GitHub Desktop.
diff array of object
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