Posted By

ozke on 06/03/08


Tagged

sort array


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

zegenvs
outbox
palmerama
ozke
THEPWN3R
tspitzr


Sort multidimensional arrays in AS3 (alphabetically)


 / Published in: ActionScript 3
 

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

  1. public function orderAlphabetically(a, b):Number{
  2. var pos:uint = 0;
  3. while(a[0].charCodeAt(pos) == b[0].charCodeAt(pos)){
  4. pos++;
  5. }
  6. var num1:uint = a[0].charCodeAt(pos);
  7. var num2:uint = b[0].charCodeAt(pos);
  8. if(isNaN(num1)){
  9. num1= 0;
  10. }
  11. if(isNaN(num2)){
  12. num2= 0;
  13. }
  14. if(num1<num2){
  15. return -1;
  16. }else if(num1>num2) {
  17. return 1;
  18. }else{
  19. return 0;
  20. }
  21. }

Report this snippet  

You need to login to post a comment.