Created
December 21, 2016 22:06
-
-
Save gmmorris/f5ed19f93e3933f10de5ac9cd86c3389 to your computer and use it in GitHub Desktop.
Revisions
-
gmmorris created this gist
Dec 21, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ function diffObjects (left, right) { const leftKeys = Object.keys(left) const rightKeys = Object.keys(right) const keyDiff = _.intersection(leftKeys, rightKeys) .reduce((differentKeys, key) => { if(_.isPlainObject(left[key]) && _.isPlainObject(right[key])) { const diff = diffObjects(left[key], right[key]) if(diff !== true) { differentKeys.push(key) } } else if(Array.isArray(left[key]) && Array.isArray(right[key])) { if(_.difference(left[key], right[key]).length) { differentKeys.push(key) } } else if (left[key] !== right[key]) { differentKeys.push(key) } return differentKeys }, _.difference(leftKeys, rightKeys)) return keyDiff.length ? keyDiff : true }