Created
November 22, 2019 07:37
-
-
Save andrIvash/40c85d458c529b9f00ed4ccea6060d34 to your computer and use it in GitHub Desktop.
get and show diff between 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