Last active
July 25, 2021 18:21
-
-
Save ToTheHit/3d70977d36fc8b3f92139102714ecf9d 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
const compareObjects = (obj1, obj2) => { | |
for (let p in obj1) { | |
if (obj1.hasOwnProperty(p) !== obj2.hasOwnProperty(p)) return false; | |
switch (typeof (obj1[p])) { | |
case 'object': | |
if (!compareObjects(obj1[p], obj2[p])) return false; | |
break; | |
case 'function': | |
if (typeof (obj2[p]) === 'undefined' || (p !== 'compare' && obj1[p].toString() !== obj2[p].toString())) return false; | |
break; | |
default: | |
if (obj1[p] !== obj2[p]) return false; | |
} | |
} | |
for (let p in obj2) { | |
if (typeof (obj1[p]) === 'undefined') return false; | |
} | |
return true; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment