Packageorg.openPyro.utils
Classpublic class ArrayUtil

A collection of Utility methods for Arrays



Public Methods
 MethodDefined by
  
createProgressiveArray(n:Number, s:Number, e:Number):Array
[static]
ArrayUtil
  
createRepeatingArray(n:Number, v:Number):Array
[static]
ArrayUtil
  
getItemIndex(src:Array, item:*):Number
[static] Returns the index number of an item in the array if that item exists.
ArrayUtil
  
insertArrayAtEnd(sourceArray:Array, arrayToInsert:Array):Array
[static] Inserts all the elements of the arrayToInsert Array into the sourceArray.
ArrayUtil
  
insertArrayAtIndex(sourceArray:Array, arrayToInsert:Array, idx:int):Array
[static]
ArrayUtil
  
insertAt(src:Array, idx:Number, data:*):void
[static] Inserts the data at the specified index of the array.
ArrayUtil
  
remove(src:Array, item:*):void
[static] Removes the FIRST instance of the item passed in as a parameter
ArrayUtil
  
removeDuplicates(arr:Array):Array
[static]
ArrayUtil
  
removeItemAt(src:Array, idx:uint):void
[static]
ArrayUtil
  
swapByIndex(src:Array, idx1:Number, idx2:Number):void
[static]
ArrayUtil
  
swapByValue(src:Array, item1:*, item2:*):void
[static] Swaps the positions of two items if they are found in the source array.
ArrayUtil
Method detail
createProgressiveArray()method
public static function createProgressiveArray(n:Number, s:Number, e:Number):ArrayParameters
n:Number
 
s:Number
 
e:Number

Returns
Array
createRepeatingArray()method 
public static function createRepeatingArray(n:Number, v:Number):ArrayParameters
n:Number
 
v:Number

Returns
Array
getItemIndex()method 
public static function getItemIndex(src:Array, item:*):Number

Returns the index number of an item in the array if that item exists. Else NaN is returned

Parameters
src:Array
 
item:*

Returns
Number
insertArrayAtEnd()method 
public static function insertArrayAtEnd(sourceArray:Array, arrayToInsert:Array):Array

Inserts all the elements of the arrayToInsert Array into the sourceArray. The elements are inserted at the end of the sourceArray. TODO: This isnt the most efficient way to do it. There is a way using splice or something.

Parameters
sourceArray:Array
 
arrayToInsert:Array

Returns
Array
insertArrayAtIndex()method 
public static function insertArrayAtIndex(sourceArray:Array, arrayToInsert:Array, idx:int):ArrayParameters
sourceArray:Array
 
arrayToInsert:Array
 
idx:int

Returns
Array
insertAt()method 
public static function insertAt(src:Array, idx:Number, data:*):void

Inserts the data at the specified index of the array. The operation is carried out on the source array and not on a copy.

Parameters
src:Array — The source Array
 
idx:Number — The index at which data needs to be inserted. The index can be greater than the length of the array, in which case, all intermediate values are initialized to undefined.
 
data:* — The data to be inserted into the Array.

Example
 
       var a:Array = [0,1,2,3,4,5]
       ArrayUtil.insertAt(a, 2, "inserted");
       trace(a) //[0,1,inserted,2,3,4,5]
       

remove()method 
public static function remove(src:Array, item:*):void

Removes the FIRST instance of the item passed in as a parameter

Parameters
src:Array
 
item:*
removeDuplicates()method 
public static function removeDuplicates(arr:Array):ArrayParameters
arr:Array

Returns
Array
removeItemAt()method 
public static function removeItemAt(src:Array, idx:uint):voidParameters
src:Array
 
idx:uint
swapByIndex()method 
public static function swapByIndex(src:Array, idx1:Number, idx2:Number):voidParameters
src:Array
 
idx1:Number
 
idx2:Number
swapByValue()method 
public static function swapByValue(src:Array, item1:*, item2:*):void

Swaps the positions of two items if they are found in the source array.

Parameters
src:Array
 
item1:*
 
item2:*