Created
August 12, 2019 07:39
-
-
Save VinayakBagaria/a3c9f0c47edf84b8a63f4631b6d42ce1 to your computer and use it in GitHub Desktop.
Deep equals on 2 variables where a is compared with b
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
function deepEquals(a, b) { | |
if(a === b) { | |
return true; | |
} | |
if(a && b && typeof a === 'object' && typeof b === 'object' && Object.keys(a).length === Object.keys(b).length && Array.isArray(a) === Array.isArray(b)) { | |
for(let key in a) { | |
if(key in b) { | |
if(!deepEquals(a[key], b[key]) { | |
return false; | |
} | |
} else { | |
return false; | |
} | |
} | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment