Skip to content

Instantly share code, notes, and snippets.

@dmi3y
Last active August 29, 2015 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmi3y/941e3ebcbeb11e08db62 to your computer and use it in GitHub Desktop.
Save dmi3y/941e3ebcbeb11e08db62 to your computer and use it in GitHub Desktop.
Deep equal - data structures object, eloquent javascript
function deepEqual(a, b) {
var
isAobj = (typeof a === 'object'),
isBobj = (typeof b === 'object'),
isABobjs = (isAobj && isBobj),
out = (a === b);
function checkX (x) {
var
ix,
res;
for ( ix in x ) {
if ( x.hasOwnProperty(ix) ) {
res = deepEqual( a[ix], b[ix]);
}
if ( !res ) {
break;
}
}
return res;
}
if ( a && b && isABobjs && !out ) {
out = checkX(a) && checkX(b);
}
return out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment