Created
September 6, 2013 18:10
-
-
Save amboy00/6467651 to your computer and use it in GitHub Desktop.
Are these two things equal
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
eq = (val1, val2) -> | |
i = undefined | |
l = undefined | |
return true if val1 is val2 | |
return false if typeof val1 isnt typeof val2 | |
if val1.length and val1.splice and val2.length and val2.splice | |
return false unless val1.length is val2.length | |
i = 0 | |
l = val1.length | |
while i < l | |
return false unless eq(val1[i], val2[i]) | |
i++ | |
return true | |
false |
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 eq( val1, val2 ){ | |
var i, l; | |
if( val1 === val2 ) { | |
return true; | |
} | |
if( typeof val1 !== typeof val2 ) { | |
return false; | |
} | |
if( val1.length && val1.splice && val2.length && val2.splice ) { | |
if( val1.length != val2.length ) { | |
return false; | |
} | |
for( i=0, l=val1.length; i<l; i++ ) { | |
if( !eq( val1[i], val2[i] ) ) { | |
return false; | |
} | |
} | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment