Last active
April 5, 2019 09:21
-
-
Save v1talii-dev/572dc8f2a84493dccb0454d4259ed22d to your computer and use it in GitHub Desktop.
JS diff 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 getObjectDiff(obj1, obj2) { | |
const diff = Object.keys(obj1).reduce((result, key) => { | |
if (!obj2.hasOwnProperty(key)) { | |
result.push(key); | |
} else if (_.isEqual(obj1[key], obj2[key])) { | |
const resultKeyIndex = result.indexOf(key); | |
result.splice(resultKeyIndex, 1); | |
} | |
return result; | |
}, Object.keys(obj2)); | |
return diff; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment