Determining the maximum value in an array without looping


<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml&#8221; creationComplete=”init()”>
<mx:Script>
<![CDATA[
import mx.collections.Sort;
import mx.collections.ArrayCollection;
private var myArray:Array = [2,3,3,4,2,2,5,6,7,2];
private var ac:ArrayCollection = new ArrayCollection(myArray);
[Bindable] private var maxValue:int = 0;
private function init():void
{
ac.sort = new Sort();
ac.refresh();
maxValue = int(ac.getItemAt(ac.length-1));
}
]]>
</mx:Script>
<mx:Label text=”Max: {maxValue}”/>
</mx:Application>

~ by mjcprasad2000 on January 29, 2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: