ArrayUtil contains fundamental methods to manipulate Arrays.
static public function clone(array:Array):ArrayClones an array.
array | the array to clone |
a clone of the passed-in array
static public function removeElement(array:Array, element):Array
Removes the given element out of the passed-in array.
array | the array to remove the element out of |
element | the element to remove |
true if element was removed and false if it was
not contained in the passed-in array
static public function removeAllOccurances(array:Array, element):Array
Removes all occurances of a the given element out of the passed-in
array.
array | the array to remove the element out of |
element | the element to remove |
List that contains the index of all removed occurances
static public function removeLastOccurance(array:Array, element):Number
Removes the last occurance of the given element out of the passed-in
array.
array | the array to remove the element out of |
element | the element to remove |
-1 if it could not be found, else the position where it had been deleted
static public function removeFirstOccurance(array:Array, element):Number
Removes the first occurance of the given element out of the passed-in
array.
array | the array to remove the element out of |
element | the element to remove |
-1 if it could not be found, else the position where it had been deleted
static public function contains(array:Array, object):Boolean
Checks if the passed-in array contains the given object.
The content is searched through with a for..in loop. This enables any type of array to be passed-in, indexed and associative arrays.
array | the array that may contain the object
|
object | the object that may be contained in the array
|
true if the array contains the object else
false
static public function indexOf(array:Array, object):Number
Returns the index of first occurance of the given object within
the passed-in array.
The content of the array is searched through by iterating through the
array. This method returns the first occurence of the passed-in object
within the array. If the object could not be found -1 will be
returned.
array | the array to search through |
object | the object to return the position of |
the position of the object within the array or -1
static public function lastIndexOf(array:Array, object):Number
Returns the index of the last occurance of the given object within
the passed-in array.
The content of the array is searched through by iterating through the
array. This method returns the last occurence of the passed-in object
within the array. If the object could not be found -1 will be
returned.
array | the array to search through |
object | the object to return the position of |
the position of the object within the array or -1
static public function shuffle(array:Array):Void
Shuffles the passed-in array.
array | the array to shuffle |
static public function swap(array:Array, i:Number, j:Number):Array
Swaps the value at position i with the value at position j of the
passed-in array.
The modifications are directly made to the passed-in array.
array | the array whose elements to swap |
i | the index of the first value |
j | the index of the second value |
array the passed-in array
| IllegalArgumentException | if the argument array is null
|
| NoSuchElementException | if the passed-in positions i and j
are less than 0 or greater than the array's length
|
static public function isSame(array1:Array, array2:Array):Boolean
Compares the two arrays array1 and array2, whether they contain
the same values at the same positions.
array1 | the first array for the comparison |
array2 | the second array for the comparison |
true if the two arrays contain the same values at the same
positions else false