Packagesekati.utils
Classpublic class ArrayUtil

Static class wrapping various Array utilities.



Public Methods
 MethodDefined by
  
ArrayUtil Static Constructor
ArrayUtil
  
asort(a:Array):Array
[static] Return alphabetically sorted array.
ArrayUtil
  
compare(aA:Array, aB:Array, hasSameOrder:Boolean = false):Boolean
[static] Compare two arrays to see if their values (and optionally order) are identical.
ArrayUtil
  
contains(a:Array, val:Object):Boolean
[static] Determines if a value exists within the array.
ArrayUtil
  
copy(a:Array):Array
[static] Create a non-unique copy of the array.
ArrayUtil
  
equals(arr1:Array, arr2:Array):Boolean
[static] Test if two arrays are identical.
ArrayUtil
  
indexOf(arr:Array, element:*):Number
[static] Wrapper for search.
ArrayUtil
  
insert(a:Array, element:Object, index:int):Array
[static] Insert an element into array at a specific index.
ArrayUtil
  
lastIndexOf(a:Array, element:*):Number
[static] Search an array for the last instance of a given element and return its index or -1.
ArrayUtil
  
locatePropVal(a:Array, prop:String, val:Object, isCaseInsensitive:Boolean = false):Object
[static] Search for a unique property/value match in an array of complex objects.
ArrayUtil
  
locatePropValIndex(a:Array, prop:String, val:Object, isCaseInsensitive:Boolean = false):Number
[static] Search for a unique property/value match in an array of complex objects and return its index in the array.
ArrayUtil
  
matchValues(aA:Array, aB:Array):Boolean
[static] Compare two arrays for a matching value.
ArrayUtil
  
max(a:Array):int
[static] Return the array index of the maximum value in a numeric array.
ArrayUtil
  
maxVal(a:Array):Number
[static] Return the maximum value in a numeric array.
ArrayUtil
  
merge(aA:Array, aB:Array):Array
[static] Merge two arrays into one.
ArrayUtil
  
min(a:Array):int
[static] Return the array index of the minimum value in a numeric array.
ArrayUtil
  
minVal(a:Array):Number
[static] Return the minimum value in a numeric array.
ArrayUtil
  
nearestNeighbor(val:Number, range:Array, returnIndex:Boolean = false):Number
[static] Locate and return the (lowest) nearest neighbor or matching value in a NUMERIC sorted array of Numbers.
ArrayUtil
  
remove(a:Array, element:Object):Array
[static] Remove all instances of an element from an array.
ArrayUtil
  
removeDuplicate(a:Array):Array
[static] Return array with duplicate entries removed.
ArrayUtil
  
search(a:Array, element:Object):Number
[static] Search an array for the first instance of a given element and return its index or -1.
ArrayUtil
  
shuffle(a:Array):void
[static] Shuffle array items.
ArrayUtil
  
sliceAll(a:Array, startIndex:int = 0, endIndex:int = 0):Array
[static] Unlike normal Array.slice(), sliceAll includes the endIndex in the return Array.
ArrayUtil
  
sliceByPropVal(a:Array, prop:String, val:Object, isCaseInsensitive:Boolean = false):Array
[static] Return a new array sliced from the original array of complex objects based on a prop/val match
ArrayUtil
  
swap(a:Array, nA:int, nB:int):Array
[static] Swap two elements positions in an array
ArrayUtil
  
uniqueCopy(a:Array):Array
[static] Create a new array that only contains unique instances of objects in the specified array.
ArrayUtil
Constructor detail
ArrayUtil()constructor
public function ArrayUtil()

ArrayUtil Static Constructor

Method detail
asort()method
public static function asort(a:Array):Array

Return alphabetically sorted array.

Parameters
a:Array

Returns
Array
compare()method 
public static function compare(aA:Array, aB:Array, hasSameOrder:Boolean = false):Boolean

Compare two arrays to see if their values (and optionally order) are identical.

Parameters
aA:Array — When false the arrays must only contain identical values, when true value & order must be identical.
 
aB:Array
 
hasSameOrder:Boolean (default = false)

Returns
Boolean

Example
    var a : Array = [ 5,4,3,2,1,'C','B','A' ];
    var b : Array = [ 'A','B','C',1,2,3,4,5 ];
    trace( "arrays (unordered) compare: " + ArrayUtil.compare( a, b ) );   // returns true
    trace( "arrays (ordered) compare: " + ArrayUtil.compare( a, b, true ) ); // returns false
   

contains()method 
public static function contains(a:Array, val:Object):Boolean

Determines if a value exists within the array.

Parameters
a:Array
 
val:Object

Returns
Boolean
copy()method 
public static function copy(a:Array):Array

Create a non-unique copy of the array.

Parameters
a:Array — array to clone.

Returns
Array — Array new array with items that are references to the original array.
equals()method 
public static function equals(arr1:Array, arr2:Array):Boolean

Test if two arrays are identical.

Parameters
arr1:Array
 
arr2:Array

Returns
Boolean
indexOf()method 
public static function indexOf(arr:Array, element:*):Number

Wrapper for search.

Parameters
arr:Array
 
element:*

Returns
Number

See also

insert()method 
public static function insert(a:Array, element:Object, index:int):Array

Insert an element into array at a specific index.

Parameters
a:Array
 
element:Object
 
index:int

Returns
Array
lastIndexOf()method 
public static function lastIndexOf(a:Array, element:*):Number

Search an array for the last instance of a given element and return its index or -1.

Parameters
a:Array
 
element:*

Returns
Number
locatePropVal()method 
public static function locatePropVal(a:Array, prop:String, val:Object, isCaseInsensitive:Boolean = false):Object

Search for a unique property/value match in an array of complex objects.

Parameters
a:Array — array of objects.
 
prop:String — array object property to locate.
 
val:Object — array object property value to match.
 
isCaseInsensitive:Boolean (default = false) — define whether prop/val should be case-insensitive (use only if search val is String).

Returns
Object — Object the first array object with the prop/val match.
locatePropValIndex()method 
public static function locatePropValIndex(a:Array, prop:String, val:Object, isCaseInsensitive:Boolean = false):Number

Search for a unique property/value match in an array of complex objects and return its index in the array.

Parameters
a:Array — array of objects.
 
prop:String — array object property to locate.
 
val:Object — array object property value to match.
 
isCaseInsensitive:Boolean (default = false) — define whether prop/val should be case-insensitive (use only if search val is String).

Returns
Number — Number the index of the first array object with the prop/val match or -1 if no match was found.
matchValues()method 
public static function matchValues(aA:Array, aB:Array):Boolean

Compare two arrays for a matching value.

Parameters
aA:Array
 
aB:Array

Returns
Boolean
max()method 
public static function max(a:Array):int

Return the array index of the maximum value in a numeric array.

Parameters
a:Array

Returns
int
maxVal()method 
public static function maxVal(a:Array):Number

Return the maximum value in a numeric array.

Parameters
a:Array

Returns
Number — Number maximum value
merge()method 
public static function merge(aA:Array, aB:Array):Array

Merge two arrays into one.

Parameters
aA:Array
 
aB:Array

Returns
Array
min()method 
public static function min(a:Array):int

Return the array index of the minimum value in a numeric array.

Parameters
a:Array

Returns
int
minVal()method 
public static function minVal(a:Array):Number

Return the minimum value in a numeric array.

Parameters
a:Array

Returns
Number — Number minimum value (0 is returned with 0 length arrays)
nearestNeighbor()method 
public static function nearestNeighbor(val:Number, range:Array, returnIndex:Boolean = false):Number

Locate and return the (lowest) nearest neighbor or matching value in a NUMERIC sorted array of Numbers.

Parameters
val:Number — the value to find match or find nearst match of.
 
range:Array — of values in array.
 
returnIndex:Boolean (default = false) — if true return the array index of the neighbor, if false return the value of the neighbor.

Returns
Number

Example
   var a : Array = [1, 3, 5, 7, 9, 11];
   var nearestLow : Number = ArrayUtil.nearestNeighbor(4, a);    // returns 3 (value)
   var nearestHigh : Number = ArrayUtil.nearestNeighbor(4, a, true);  // returns 1 (index) 
   

remove()method 
public static function remove(a:Array, element:Object):Array

Remove all instances of an element from an array.

Parameters
a:Array
 
element:Object

Returns
Array
removeDuplicate()method 
public static function removeDuplicate(a:Array):Array

Return array with duplicate entries removed.

Parameters
a:Array

Returns
Array
search()method 
public static function search(a:Array, element:Object):Number

Search an array for the first instance of a given element and return its index or -1.

Parameters
a:Array
 
element:Object

Returns
Number
shuffle()method 
public static function shuffle(a:Array):void

Shuffle array items.

Parameters
a:Array
sliceAll()method 
public static function sliceAll(a:Array, startIndex:int = 0, endIndex:int = 0):Array

Unlike normal Array.slice(), sliceAll includes the endIndex in the return Array.

Parameters
a:Array — source array
 
startIndex:int (default = 0) — A number specifying the index of the starting point for the slice. If startIndex is a negative number, the starting point begins at the end of the array, where -1 is the last element.
 
endIndex:int (default = 0) — A number specifying the index of the ending point for the slice. If you omit this parameter, the slice includes all elements from the starting point to the end of the array. If endIndex is a negative number, the ending point is specified from the end of the array, where -1 is the last element.

Returns
Array — An array that consists of a range of elements from the original array.
sliceByPropVal()method 
public static function sliceByPropVal(a:Array, prop:String, val:Object, isCaseInsensitive:Boolean = false):Array

Return a new array sliced from the original array of complex objects based on a prop/val match

Parameters
a:Array — array of objects.
 
prop:String — array object property to locate.
 
val:Object — array object property value to match.
 
isCaseInsensitive:Boolean (default = false) — define whether prop/val should be case-insensitive (use only if search val is String).

Returns
Array — Array of objects that contain the prop/val match.
swap()method 
public static function swap(a:Array, nA:int, nB:int):Array

Swap two elements positions in an array

Parameters
a:Array
 
nA:int
 
nB:int

Returns
Array

Throws
— on invalid array index
uniqueCopy()method 
public static function uniqueCopy(a:Array):Array

Create a new array that only contains unique instances of objects in the specified array. this can be used to remove duplication object instances from an array.

Parameters
a:Array

Returns
Array