Created
July 28, 2017 05:27
-
-
Save chris-muller/505d38d1ec643d349eb51eb3c59ad850 to your computer and use it in GitHub Desktop.
Compare two objects
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 characters
function compare(newField, oldField) { | |
var isClean = true; | |
for (var property in newField) { | |
if (!newField.hasOwnProperty(property)) { continue; } | |
if(property == 'options') { | |
const newOptions = newField.options; | |
const oldOptions = oldField.options; | |
var optionsClean = true; | |
for (var i = 0; i < newOptions.length; i++) { | |
const optionMatches = newOptions[i] === oldOptions[i]; | |
if(!optionMatches) { | |
optionsClean = false; | |
break; | |
} | |
} | |
if(!optionsClean) { | |
isClean = false; | |
break; | |
} else { | |
continue; | |
} | |
} | |
const propMatches = oldField[property] === newField[property]; | |
if(!propMatches){ | |
isClean = false; | |
break; | |
} | |
} | |
return isClean; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment