Created
November 5, 2009 02:59
-
-
Save rafaelrinaldi/226664 to your computer and use it in GitHub Desktop.
Sort unidimensional arrays.
This file contains 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
package rinaldi.array { | |
/** | |
* | |
* Sort unidimensional arrays. | |
* The funcionality of this method is based in one technique teached in ActionScript 3.0 Cookbook. | |
* | |
* @param p_array Array to sort. | |
* | |
* @return A sorted array. | |
* | |
**/ | |
public function sortArray( p_array : Array ) : Array | |
{ | |
var indices : Array = p_array.sort(Array.RETURNINDEXEDARRAY); // Getting an array with numeric indices | |
var sorted : Array = []; | |
for(var i : int = 0, indice : Number; i < p_array.length; i++) { | |
indice = indices[i]; | |
sorted.push(p_array[indice]); | |
} | |
// Removing references | |
indices = null; | |
p_array = null; | |
return sorted; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment