Skip to content

Instantly share code, notes, and snippets.

@bhandarisaurav
Created September 25, 2021 23:54
Show Gist options
  • Save bhandarisaurav/e669cf6c6647d4e7320dbff5311be606 to your computer and use it in GitHub Desktop.
Save bhandarisaurav/e669cf6c6647d4e7320dbff5311be606 to your computer and use it in GitHub Desktop.
get difference of 2 objects
function difference(object, base) {
function changes(object, base) {
return _.transform(object, function (result, value, key) {
if (!_.isEqual(value, base[key])) {
result[key] =
_.isObject(value) && _.isObject(base[key])
? changes(value, base[key])
: value;
}
});
}
return changes(object, base);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment