AS3 numerical array sorting?
16,713
Solution 1
Have you tried:
dataArray.sort( Array.NUMERIC );
dataObjectArray.sortOn( ["uid"], [Array.NUMERIC]);
Solution 2
Surprisingly, as3 has in-built functions for this.
dataArray.sort(Array.NUMERIC);
dataObjectArray.sortOn("uid", Array.NUMERIC);
This would elegantly give the effect desired: Ascending order is by default. The array documentation covers additional details, such as descending order/etc... Lol sortOn even sorts nested objects / array if the field values are provided.
Author by
PicoCreator
Updated on June 15, 2022Comments
-
PicoCreator about 2 years
var dataArray:Array = [ 5, 6, 3, 8, 10, 11, 32, 2 ]; var dataObjectArray:Array [ { "uid": 5 }, { "uid": 6 .... Similar to above ... } ];
I have the above 2 arrays in AS3. and i wish to sort them numerically (1 ~ X) in order [Skipping those that does not exist]. What is the best and most efficent way to do so for dataArray / dataObjectArray.
You may solve 1, or both =)
-
PicoCreator almost 13 yearsHaha, just did: posted it too 2mins before you. Took some time to find something so convienent though
-
goliatone almost 13 years@pico.creator: SO should somehow let you know that someone has posted an answer while you are still writing yours ;) tnxs anyways for the mark.
-
PicoCreator almost 13 yearsIt was certainly a surprise =] : Giving myself the answer is just ~wierd~ anyway, haha