Consider:
myArray.sortOn( "1", Array.NUMERIC );
>From a quick test this is 2-3 times faster than the callback "compare" way.
10K entries sorted in:
sortOn(1) : 5ms
sort(compare) : 13ms
This works because array indices are considered as keys just like normal
objects.
cheers
~neo
-----Original Message-----
From: eka [mailto:[EMAIL PROTECTED]
Sent: 01 February 2007 07:25 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] sort 2d array
Hello :)
you must creates benchs to test all solutions but the first is the sort()
method with a custom method
var myArray:Array = [
[20,40],
[20,10],
[30,15],
[30,35],
[40,100],
[1000,1]
];
var compare:Function = function ( a , b ) {
if ( a[1] < b[1] )
{
return -1 ;
}
else if (a[1] > b[1] )
{
return 1 ;
}
else
{
return 0 ;
}
}
trace(myArray) ;
myArray.sort( compare ) ;
trace(myArray) ;
I think the Actionscript in FP8 or FP9 really speed !
EKA+ :)
2007/2/1, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
>
>
>
> Hello,
>
> Can anybody tell me how to sort the following array based upon the
> second value within each array item
>
> myArray:Array = [ [20,40],[20,10],[30,15],[30,35],[40,100],[1000,1]];
>
> this should be something like
>
> [[1000,1], [20,10], .....
>
> Faster the better cos its for a game and gets called a lot of times.
>
>
> regards
>
> _______________________________________________
> [email protected]
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com http://training.figleaf.com
>
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com