Created
February 21, 2019 20:25
-
-
Save garenyondem/ecb227becd4744e7ff72d615778cfb58 to your computer and use it in GitHub Desktop.
Diff using Lodash
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
module.exports = function difference(object, base) { | |
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(object, base); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment