Posted By

ozke on 05/21/08


Tagged

sort array


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

outbox
ozke
THEPWN3R
thastylos
tspitzr


Sort multidimensional arrays in AS3 (numerically)


 / Published in: ActionScript 3
 

I have fixed and improved some code I found on the Internet

  1. public function orderNumerically(a, b):Number{
  2. // Change a[0] & b[0] by a[i] & b[i]
  3. // (where i is the array index you want to use to sort the multidimensional array)
  4. var num1 = Number(a[0]);
  5. var num2 = Number(b[0]);
  6. if(num1<num2){
  7. return -1;
  8. }else if(num1>num2) {
  9. return 1;
  10. }else{
  11. return 0;
  12. }
  13. }
  14. the_array.sort(orderNumerically);

Report this snippet  

You need to login to post a comment.