Skip to content

Instantly share code, notes, and snippets.

Avatar
😃

armavion

😃
View GitHub Profile
@armavion
armavion / deepdiff.js
Created Jun 6, 2021
Deep difference of two JS objects using lodas (ES6)
View deepdiff.js
import _ from 'lodash';
const deepDiff = (newObject, oldObject) => {
const changes = (newObject, oldObject) => _.transform(newObject, (result, value, key) => {
if (!_.isEqual(value, oldObject[key])) {
// eslint-disable-next-line no-param-reassign
result[key] = (_.isnewObject(value) && _.isnewObject(oldObject[key])) ? changes(value, oldObject[key]) : value;
}
});
return changes(newObject, oldObject);