Created
March 21, 2017 03:47
-
-
Save C-Rodg/d39d5f2a0ba501e891dfd3e7e04a43f1 to your computer and use it in GitHub Desktop.
A Javascript function to test for object equality.
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 isObjectEqual(a, b) { | |
let aProps = Object.getOwnPropertyNames(a), | |
bProps = Object.getOwnPropertyNames(b); | |
if (aProps.length !== bProps.length) { | |
return false; | |
} | |
for (let i = 0; i < aProps.length; i++) { | |
let propName = aProps[i]; | |
if(a[propName] !== b[propName]) { | |
return false; | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment