Public Constants
 ConstantDefined By
  contains : Function
Determines whether the specified object exists as an element in an Array object.
core.arrays
  initialize : Function
Initializes a new Array with an arbitrary number of elements (index), with every element containing the passed parameter value or by default the null value.
core.arrays
  pierce : Function
Splices an array (removes an element) and returns either the entire array or the removed element.
core.arrays
  reduce : Function
Apply a function simultaneously against two values of the array (from left-to-right) as to reduce it to a single value.
core.arrays
  reduceRight : Function
Apply a function simultaneously against two values of the array (from right-to-left) as to reduce it to a single value.
core.arrays
  repeat : Function
Returns a new Array who contains the specified Array elements repeated count times.
core.arrays
  shuffle : Function
Shuffles an array.
core.arrays
  spliceInto : Function
Splice one array into another.
core.arrays
Constant Detail
containsConstant
public const contains:Function

Determines whether the specified object exists as an element in an Array object.

Example :

     import core.arrays.contains ;
     
     var ar:Array = [2, 3, 4] ;
     
     trace( contains( ar , 3 ) ) ; // true
     trace( contains( ar , 5 ) ) ; // false
     

initializeConstant 
public const initialize:Function

Initializes a new Array with an arbitrary number of elements (index), with every element containing the passed parameter value or by default the null value.

Example :

     import core.arrays.initialize ;
     
     var testO:Array = initialize( 3 ) ; // [null,null,null]
     var test1:Array = initialize( 3 , 0 ) ; // [0,0,0]
     var test2:Array = initialize( 3 , true ) ; // [true,true,true]
     var test3:Array = initialize( 4 , "" ) ; // ["","","",""]
     

pierceConstant 
public const pierce:Function

Splices an array (removes an element) and returns either the entire array or the removed element.

Example :

     import core.arrays.pierce ;
     
     var ar:Array = [0,1,2,3,4,5] ;
      
     trace( ar ) ; // 0,1,2,3,4,5
     
     trace( "pierce( ar, 1 ) : " + pierce( ar, 1 ) ) ; // pierce(ar,1) : 1
     trace( "pierce( ar, 1 ) : " + pierce( ar, 1 ) ) ; // pierce(ar,1) : 2
     
     trace( ar ) ; // 0,3,4,5
     
     trace( pierce( ar, 1 , true ) ) ; // 0,4,5
     

reduceRightConstant 
public const reduceRight:Function

Apply a function simultaneously against two values of the array (from right-to-left) as to reduce it to a single value.

The reduceRight method executes the callback function once for each element present in the array, excluding holes in the array, receiving four arguments: the initial value (or value from the previous callback call), the value of the current element, the current index, and the array over which iteration is occurring.

The call to the reduceRight callback would look something like this :

     function callback( previousValue:, currentValue:, index:uint , array:Array ):     {
         // ...
     }
     

The first time the function is called, the previousValue and currentValue can be one of two values. If an initialValue was provided in the call to reduceRight, then previousValue will be equal to initialValue and currentValue will be equal to the last value in the array. If no initialValue was provided, then previousValue will be equal to the last value in the array and currentValue will be equal to the second-to-last value.

Example :

     import core.arrays.reduceRight ;
     
     var ar:Array ;
     var result:;
     var callback:Function ;
     
     ////// only to debug in the the Array trace message
     Array.prototype.toString = function():String
     {
         return "[" + this.join(",") + "]" ;
     }
     //////
     
     ar = [0,1,2,3,4] ;
     
     callback = function( previousValue:, currentValue:, index:int, array:Array ):     {
         trace( "previousValue = " + previousValue + ", currentValue = " + currentValue + ", index = " + index ) ;
         return previousValue + currentValue ;
     } ;
     
     result = Arrays.reduceRight( ar , callback ) ;
     // previousValue = 4, currentValue = 3, index = 3 // First call
     // previousValue = 7, currentValue = 2, index = 2 // Second call
     // previousValue = 9, currentValue = 1, index = 1 // Third call
     // previousValue = 10, currentValue = 0, index = 0 // Fourth call
     trace( "value : " + result ) ;  // value : 10
     
     result = Arrays.reduceRight( ar , callback , 10 ) ;
     // previousValue = 10, currentValue = 4, index = 4
     // previousValue = 14, currentValue = 3, index = 3
     // previousValue = 17, currentValue = 2, index = 2
     // previousValue = 19, currentValue = 1, index = 1
     // previousValue = 20, currentValue = 0, index = 0
     trace( "value : " + result ) ;  // value : 20
     
     // array is always the object [0,1,2,3,4] upon which reduce was called
     
     trace( "ar : " + ar ) ; // ar : [0,1,2,3,4]
     
     trace("--- Example: Sum up all values within an array") ;
     
     ar = [0, 1, 2, 3] ;
     
     callback = function( a:uint , b:uint , ...args:Array ):     { 
         return a + b ;
     }
     
     result = Arrays.reduceRight( ar , callback );
     trace("total : " + result ) ; // total == 6
     
     trace("--- Example: Flatten an array of arrays") ;
     
     ar = [[0,1], [2,3], [4,5]] ;
     
     callback = function( a:Array , b:Array , ...args:Array ):     {
         return a.concat( b ) ;
     }
     
     result = Arrays.reduceRight( ar , callback , [] ) ;
     trace("flattened is " + result ) ; // flattened is [4, 5, 2, 3, 0, 1]
     

reduceConstant 
public const reduce:Function

Apply a function simultaneously against two values of the array (from left-to-right) as to reduce it to a single value.

The reduce method executes the callback function once for each element present in the array, excluding holes in the array, receiving four arguments: the initial value (or value from the previous callback call), the value of the current element, the current index, and the array over which iteration is occurring.

This method reduce is an extension to the ECMA-262 standard; (see Javascript 1.8 new implementation) as such it may not be present in other implementations of the standard.

The call to the reduce callback would look something like this:

     function callback( previousValue:, currentValue:, index:uint , array:Array ):     {
         // ...
     }
     

The first time the function is called, the previousValue and currentValue can be one of two values.

If an initialValue was provided in the call to reduce, then previousValue will be equal to initialValue and currentValue will be equal to the first value in the array.

If no initialValue was provided, then previousValue will be equal to the first value in the array and currentValue will be equal to the second.

Example :

     import core.arrays.reduce ;
     
     var ar:Array ;
     var result:;
     var callback:Function ;
     
     ////// only to debug in the the Array trace message
     Array.prototype.toString = function():String
     {
         return "[" + this.join(",") + "]" ;
     }
     //////
      
     ar = [0,1,2,3,4] ;
     
     callback = function( previousValue:, currentValue:, index:int, array:Array ):     {
         trace( "previousValue = " + previousValue + ", currentValue = " + currentValue + ", index = " + index ) ;
         return previousValue + currentValue ;
     } ;
     
     ////
     
     result = reduce( ar , callback ) ;
      
     // previousValue = 0, currentValue = 1, index = 1 // First call
     // previousValue = 1, currentValue = 2, index = 2 // Second call
     // previousValue = 3, currentValue = 3, index = 3 // Third call
     // previousValue = 6, currentValue = 4, index = 4 // Fourth call
      
     trace( "value : " + result ) ;  // value : 10
     
     ////
     
     result = reduce( ar , callback , 10 ) ;
      
     // previousValue = 10, currentValue = 0, index = 0
     // previousValue = 10, currentValue = 1, index = 1
     // previousValue = 11, currentValue = 2, index = 2
     // previousValue = 13, currentValue = 3, index = 3
     // previousValue = 16, currentValue = 4, index = 4
     
     trace( "value : " + result ) ;  // value : 20
     
     ////
     
     // array is always the object [0,1,2,3,4] upon which reduce was called
     trace( "ar : " + ar ) ; // ar : 0,1,2,3,4
     
     trace("--- Example: Sum up all values within an array") ;
     
     ar = [0, 1, 2, 3] ;
     
     callback = function( a:uint , b:uint , ...args:Array ):     {
         return a + b ; 
     }
     
     result = reduce( ar , callback );
     trace("total : " + result ) ; // total == 6
     
     trace("--- Example: Flatten an array of arrays") ;
     
     ar = [[0,1], [2,3], [4,5]] ;
     callback = function( a:Array , b:Array , ...args:Array ):     {
         return a.concat( b ) ;
     }
     
     result = reduce( ar , callback , [] ) ;
     trace("flattened is " + result ) ; // flattened is [0, 1, 2, 3, 4, 5]
     

repeatConstant 
public const repeat:Function

Returns a new Array who contains the specified Array elements repeated count times.

Example :

     import core.arrays.repeat ;
     
     var ar:Array = [2, 3, 4] ;
     
     trace( repeat( ar , 0 ) ) ; // 2,3,4
     trace( repeat( ar , 3 ) ) ; // 2,3,4,2,3,4,2,3,4
     

shuffleConstant 
public const shuffle:Function

Shuffles an array.

Example :

     import core.arrays.shuffle ;
     
     var ar:Array = [0,1,2,3,4,5,6,7,8,9] ;
     
     trace( ar ) ;
     shuffle( ar ) ;
     trace( ar ) ;
     

spliceIntoConstant 
public const spliceInto:Function

Splice one array into another.

Example :

     import core.arrays.spliceInto ;
     
     var inserted:Array  ;
     var container:Array ;
     
     inserted  = [1, 2, 3, 4] ;
     container = [5, 6, 7, 8] ;
     
     trace( "inserted  : " + inserted  ) ;
     trace( "container : " + container ) ;
     
     trace("---") ;
     
     inserted  = [1, 2, 3, 4] ;
     container = [5, 6, 7, 8] ;
     
     spliceInto( inserted, container ) ;
     trace( "spliceInto( inserted, container, 0 , 0 ) : " + container ) ; // 1,2,3,4,5,6,7,8
     
     trace("---") ;
     inserted  = [1, 2, 3, 4] ;
     container = [5, 6, 7, 8] ;
     
     spliceInto( inserted, container, 0 , 4 ) ;
     trace( "spliceInto( inserted, container, 0 , 4 ) : " + container ) ; // 1,2,3,4
     
     trace("---") ;
     
     inserted  = [1, 2, 3, 4] ;
     container = [5, 6, 7, 8] ;
     
     spliceInto( inserted, container, 0 , 2 ) ;
     trace( "spliceInto( inserted, container, 0 , 2 ) : " + container ) ; // 1,2,3,4,7,8