-
-
Save TimBlock/77c7c53277e565d7563d 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
// Your code here. | |
function deepEqual(obj1,obj2){ | |
if(obj1===obj2) return true; | |
if (obj1 == null || typeof obj1 != "object" || | |
obj2 == null || typeof obj2 != "object") | |
return false; | |
var propObj1 = 0, propObj2 = 0; | |
for (var prop in obj1) | |
propObj1 += 1; | |
for (var prop in obj2) { | |
propObj2 += 1; | |
if (!(prop in obj1) || !deepEqual(obj1[prop], obj2[prop])) | |
return false; | |
} | |
return propObj1 == propObj2; | |
} | |
var obj = {here: {is: "an"}, object: 2}; | |
console.log(deepEqual(obj, obj)); | |
// → true | |
console.log(deepEqual(obj, {here: 1, object: 2})); | |
// → false | |
console.log(deepEqual(obj, {here: {is: "an"}, object: 2})); | |
// → true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment