Skip to content

Instantly share code, notes, and snippets.

@chris-muller
Created July 28, 2017 05:27
Show Gist options
  • Save chris-muller/505d38d1ec643d349eb51eb3c59ad850 to your computer and use it in GitHub Desktop.
Save chris-muller/505d38d1ec643d349eb51eb3c59ad850 to your computer and use it in GitHub Desktop.
Compare two objects
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