开发者

Get shortest number Algorithm, in actionscript syntax

开发者 https://www.devze.com 2022-12-27 13:01 出处:网络
I want to put shortest int in shortest: shortest = 500; for(i = 1; i <= _global.var_process_count; i++)开发者_运维问答

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 a Number.
  • 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);
0

精彩评论

暂无评论...
验证码 换一张
取 消