Skip to content

Instantly share code, notes, and snippets.

@rafaelrinaldi
Created November 5, 2009 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelrinaldi/226664 to your computer and use it in GitHub Desktop.
Save rafaelrinaldi/226664 to your computer and use it in GitHub Desktop.
Sort unidimensional arrays.
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