Skip to content

Instantly share code, notes, and snippets.

@edgarberm
Last active July 14, 2016 15:46
Show Gist options
  • Save edgarberm/b4a8c66070e2341e8b4431ba9f4934a3 to your computer and use it in GitHub Desktop.
Save edgarberm/b4a8c66070e2341e8b4431ba9f4934a3 to your computer and use it in GitHub Desktop.
Find differences between two objects
const contains = (key, list) => {
return list.indexOf(key) > -1;
}
const diff = (first, second) => {
let firstKeys = Object.keys(first);
let secondKeys = Object.keys(second);
let addition = secondKeys.filter(key => !contains(key, firstKeys))
let deletion = firstKeys.filter(key => !contains(key, secondKeys))
return {addition, deletion}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment