Created
May 10, 2010 14:07
-
-
Save jbrantly/396073 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
var hasOwnProperty = Object.prototype.hasOwnProperty; | |
var equivalent = function(actual, expected) { | |
if (actual === expected) { | |
return true; | |
} | |
else if (expected instanceof Date) { | |
if (actual instanceof Date && actual.getTime() == expected.getTime()) { | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
else if (typeof actual != "object" && typeof expected != "object") { | |
return actual == expected; | |
} | |
else { | |
if (actual.prototype !== expected.prototype) { | |
return false; | |
} | |
var actualLength = 0, expectedLength = 0; | |
for (var prop in actual) { | |
if (hasOwnProperty.call(actual, prop)) { | |
actualLength++; | |
if (!hasOwnProperty.call(expected, prop) || !equivalent(actual[prop], expected[prop])) { | |
return false; | |
} | |
} | |
} | |
for (var prop in expected) { | |
if (hasOwnProperty.call(expected, prop)) { | |
expectedLength++; | |
} | |
} | |
return actualLength == expectedLength; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment