"Jeff Thies" <no****@nospam.net> writes:
I need to check if two hashes are identical.
What is a hash?
My guess is that it is an array that you use to store values in. You
use it as a hash *table* (and you should just use a plain object, not
an array).
My thoughts are something like this:
function compareHash(hash1,hash2){
if(hash1.length != hash2.length){return false}
Not really interesting if you have an array. Not interesting at all if
you don't.
for(var key in hash1){
if(hash1[key] != hash2[key]) return false;
You should compare with !== instead. Otherwise this comparison of two
clearly different objects gives true:
compareHash({key:0},{key:false})
Have I missed something, or is there a more direct approach?
Use objects for hash tables, drop the length comparison, and use !==.
/L
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'