Last active
July 14, 2016 15:46
-
-
Save edgarberm/b4a8c66070e2341e8b4431ba9f4934a3 to your computer and use it in GitHub Desktop.
Find differences between two objects
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
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