[thelist] Programming - Finding Largest Value

Erik Mattheis gozz at gozz.com
Wed Mar 20 08:20:09 CST 2002


>_level0.biggest = _level0.var1
>
>for (i=1; i<9; i++) {
>     if (_level0["var" + i] > _level0.biggest) {
>     _level0.biggest = _level0["var" + i];
>     }
>}
>
>The script isn't returning the correct value for the variable
>"biggest."  I'm sure the same logic applies to any language, could
>someone tell me why this function doesn't work?

What datatypes are the values of your variables? If they're all
numbers, that should do fine.

You may be able to see what's throwing it off it you trace the logic
it's looping through:

for (var i=1; i<9; i++) {
     trace(_level0["var" + i] + '>' + _level0.biggest);
     if (_level0["var" + i] > _level0.biggest) {
         trace('this is true: ' _level0["var" + i] + '>' + _level0.biggest);
         _level0.biggest = _level0["var" + i];
     }
}

trace('the biggest value: ' + _level0.biggest);

>Or can anyone suggest another means to find the largest value of a group?

Put them in an array and use Array.sort()



--

__________________________________________
- Erik Mattheis

(612) 377 2272
http://goZz.com/

__________________________________________



More information about the thelist mailing list