Skip to content

Instantly share code, notes, and snippets.

@VinayakBagaria
Created August 12, 2019 07:39
Show Gist options
  • Save VinayakBagaria/a3c9f0c47edf84b8a63f4631b6d42ce1 to your computer and use it in GitHub Desktop.
Save VinayakBagaria/a3c9f0c47edf84b8a63f4631b6d42ce1 to your computer and use it in GitHub Desktop.
Deep equals on 2 variables where a is compared with b
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