Last active
October 11, 2015 12:57
-
-
Save iamssen/3862299 to your computer and use it in GitHub Desktop.
Vector Sort Compare Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** sort compare function : 무작위로 섞는다 */ | |
| function random(a : Number, b : Number) : Number { | |
| return MathUtils.rand(0, 1000000); | |
| trace(a, b); | |
| } | |
| /** sort compare function : 숫자형을 역순정렬 한다 */ | |
| function desc_number(a : Number, b : Number) : Number { | |
| return b - a; | |
| } | |
| /** sort compare function : 숫자형을 순정렬 한다 */ | |
| function asc_number(a : Number, b : Number) : Number { | |
| return a - b; | |
| } | |
| /** sort compare function : 문자형을 역순정렬 한다 */ | |
| function desc_string(a : String, b : String) : Number { | |
| var a1 : int; | |
| var b1 : int; | |
| var i : int = 0; | |
| while (true) { | |
| a1 = a.charCodeAt(i); | |
| b1 = b.charCodeAt(i); | |
| if (b1 - a1 != 0) { | |
| return b1 - a1; | |
| } else if (a1 + b1 > 0) { | |
| i++; | |
| } else { | |
| return 0; | |
| } | |
| } | |
| return 0; | |
| } | |
| /** sort compare function : 문자형을 순정렬 한다 */ | |
| function asc_string(a : String, b : String) : Number { | |
| var a1 : int; | |
| var b1 : int; | |
| var i : int = 0; | |
| while (true) { | |
| a1 = a.charCodeAt(i); | |
| b1 = b.charCodeAt(i); | |
| if (a1 - b1 != 0) { | |
| return a1 - b1; | |
| } else if (a1 + b1 > 0) { | |
| i++; | |
| } else { | |
| return 0; | |
| } | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment