Skip to content

Instantly share code, notes, and snippets.

@SakoMe
Created January 14, 2018 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SakoMe/6cacc3b06115d11263ce7647e04c53ae to your computer and use it in GitHub Desktop.
Save SakoMe/6cacc3b06115d11263ce7647e04c53ae to your computer and use it in GitHub Desktop.
helper to compare objects...
Object.equals = (x, y) => {
if (x === y) return true;
if (!(x instanceof Object) || !(y instanceof Object)) return false;
if (x.constructor !== y.constructor) return false;
for (let p in x) {
if (!x.hasOwnProperty(p)) continue;
if (!y.hasOwnProperty(p)) return false;
if (x[p] === y[p]) continue;
if (typeof x[p] !== 'object') return false;
if (!Object.equals(x[p], y[p])) return false;
}
for (p in y) {
if (y.hasOwnProperty(p) && !x.hasOwnProperty(p)) return false;
}
return true;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment