Created
November 5, 2017 17:28
-
-
Save abdulhalim-cu/d21443d5693640c981042cfcfd803dba 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 deepEqual(a, b) { | |
if (a === b) return true; | |
if (a == null || typeof a != "object" || | |
b == null || typeof b != "object") | |
return false; | |
var propsInA = 0, propsInB = 0; | |
for (var prop in a) | |
propsInA += 1; | |
for (var prop in b) { | |
propsInB += 1; | |
if (!(prop in a) || !deepEqual(a[prop], b[prop])) | |
return false; | |
} | |
return propsInA == propsInB; | |
} | |
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