Get shortest number Algorithm, in actionscript syntax
I want to put shortest int in shortest
:
shortest = 500;
for(i = 1; i <= _global.var_process_count; i++)开发者_运维问答
{
if(_root["process" + i].process_time_original.text < shortest)
shortest = _root["process" + i].process_time_original.text ;
}
what's wrong with above lines of code?
- The code is not ActionScript-3, it is either AS-2 or lower.
- You are not casting the string (
textfield.text
) to aNumber
. - What if the smallest number is 501 (or anything greater than 500)?
Try the following code:
var shortest:Number = Number.MAX_VALUE;
for(i = 1; i <= _global.var_process_count; i++)
{
var t:Number = Number(_root["process" + i].process_time_original.text);
if(isNaN(t)) //in case the text is not a valid number.
continue;
if(t < shortest)
shortest = t;
}
trace("shortest number is " + shortest);
精彩评论