Sort multidimensional arrays in AS3 (alphabetically)


/ Published in: ActionScript 3
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.