Created
October 1, 2017 08:08
-
-
Save tkssharma/f1a6c495cb513cb1163f04304ef40c60 to your computer and use it in GitHub Desktop.
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 isEquivalent(a, b) { | |
// Create arrays of property names | |
var aProps = Object.getOwnPropertyNames(a); | |
var bProps = Object.getOwnPropertyNames(b); | |
// If number of properties is different, | |
// objects are not equivalent | |
if (aProps.length != bProps.length) { | |
return false; | |
} | |
for (var i = 0; i < aProps.length; i++) { | |
var propName = aProps[i]; | |
// If values of same property are not equal, | |
// objects are not equivalent | |
if (a[propName] !== b[propName]) { | |
return false; | |
} | |
} | |
return true; | |
} | |
// Outputs: true | |
console.log(isEquivalent(bobaFett, jangoFett)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment