Created
December 17, 2018 21:39
-
-
Save Bengejd/61f9f502fd34e924091f07417707f448 to your computer and use it in GitHub Desktop.
Deep Diff between two objects, using Lodash - Supports nested arrays.
This file contains 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
getDiff() { | |
function changes(object, base) { | |
let arrayIndexCounter = 0; | |
return _.transform(object, function (result, value, key) { | |
if (!_.isEqual(value, base[key])) { | |
let resultKey = _.isArray(base) ? arrayIndexCounter++ : key; | |
result[resultKey] = (_.isObject(value) && _.isObject(base[key])) ? changes(value, base[key]) : value; | |
console.log("Result: " + JSON.stringify(result)); | |
} | |
}); | |
} | |
return changes(compareObject, baseObject); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment