Last active
February 17, 2020 20:04
-
-
Save bobmacneal/09a14032eb3d31e58aa9e0d0d88292a0 to your computer and use it in GitHub Desktop.
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
import isEqual from 'lodash/isEqual' | |
import isObject from 'lodash/isObject' | |
import transform from 'lodash/transform' | |
export const diffBetweenTwoObjects = (object, base) => { | |
const changes = (object, base) => { | |
return transform(object, (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