Skip to content

Instantly share code, notes, and snippets.

@garenyondem
Created February 21, 2019 20:25
Show Gist options
  • Save garenyondem/ecb227becd4744e7ff72d615778cfb58 to your computer and use it in GitHub Desktop.
Save garenyondem/ecb227becd4744e7ff72d615778cfb58 to your computer and use it in GitHub Desktop.
Diff using Lodash
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