| Method | Defined by | ||
|---|---|---|---|
|
contains(ar:Array, value:Object):Boolean
[static]
Returns whether the Array contains a particular item.
| Arrays | ||
|
initialize(elements:uint = 0, value:* = null):Array
[static]
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.
| Arrays | ||
|
reduce(ar:Array, callback:Function, initialValue:*):*
[static]
Apply a function simultaneously against two values of the array (from left-to-right) as to reduce it to a single value.
| Arrays | ||
|
reduceRight(ar:Array, callback:Function, initialValue:*):*
[static]
Apply a function simultaneously against two values of the array (from right-to-left) as to reduce it to a single value.
| Arrays | ||
|
repeat(ar:Array, count:uint = 0):Array
[static]
Returns a new Array who contains the specified Array elements repeated count times.
| Arrays | ||
|
spliceInto(inserted:Array, container:Array, containerPosition:Number = 0, countReplaced:Number = 0):void
[static]
Splice one array into another.
| Arrays | ||
| contains | () | method |
public static function contains(ar:Array, value:Object):BooleanReturns whether the Array contains a particular item.
Example :
import system.Arrays ;
var ar:Array = [2, 3, 4] ;
trace( Arrays.contains(ar, 3) ) ; // true
trace( Arrays.contains(ar, 5) ) ; // false
Parameters
ar:Array — The search Array.
|
|
value:Object — The value to search.
|
Boolean — whether the Array contains a particular item.
|
| initialize | () | method |
public static function initialize(elements:uint = 0, value:* = null):ArrayInitializes 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 :
var test:Array = Arrays.initialize( 3 ); //define [null,null,null] var test1:Array = Arrays.initialize( 3, 0 ); //define [0,0,0] var test2:Array = Arrays.initialize( 3, true ); //define [true,true,true] var test3:Array = Arrays.initialize( 3, "" ); //define ["","",""]Parameters
elements:uint (default = 0) |
|
value:* (default = null) |
Array — a new Array with an arbitrary number of elements (index),
with every element containing the passed parameter value or by default the null value.
|
| reduce | () | method |
public static function reduce(ar:Array, callback:Function, initialValue:*):*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.
Basic example :
Example :
import system.Arrays ;
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.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 = Arrays.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 = Arrays.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 = Arrays.reduce( ar , callback , [] ) ;
trace("flattened is " + result ) ; // flattened is [0, 1, 2, 3, 4, 5]
Parameters
ar:Array — Function to execute on each value in the Array.
|
|
callback:Function — The object to use as the first argument to the first call of the callback.
|
|
initialValue:* |
* |
| reduceRight | () | method |
public static function reduceRight(ar:Array, callback:Function, initialValue:*):*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 system.Arrays ;
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]
Parameters
ar:Array — Function to execute on each value in the Array.
|
|
callback:Function — The object to use as the first argument to the first call of the callback.
|
|
initialValue:* |
* |
| repeat | () | method |
public static function repeat(ar:Array, count:uint = 0):ArrayReturns a new Array who contains the specified Array elements repeated count times.
Example :
import system.Arrays ;
var ar:Array = [2, 3, 4] ;
trace( Arrays.repeat(ar, 0) ) ; // 2,3,4
trace( Arrays.repeat(ar, 3) ) ; // 2,3,4,2,3,4,2,3,4
Parameters
ar:Array |
|
count:uint (default = 0) |
Array — a new Array who contains the specified Array elements repeated count times.
|
| spliceInto | () | method |
public static function spliceInto(inserted:Array, container:Array, containerPosition:Number = 0, countReplaced:Number = 0):voidSplice one array into another. Like the python
container[containerPosition:containerPosition + countReplaced] = inserted
Parameters
inserted:Array — The Array of char inserted in the Array container.
|
|
container:Array — The container modified in place.
|
|
containerPosition:Number (default = 0) — The position in the container to inserted the Array of chars.
|
|
countReplaced:Number (default = 0) — The count value to replaced values.
|
import system.Arrays ;
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] ;
Arrays.spliceInto( inserted, container ) ;
trace( "Arrays.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] ;
Arrays.spliceInto( inserted, container, 0 , 4 ) ;
trace( "Arrays.spliceInto( inserted, container, 0 , 4 ) : " + container ) ; // 1,2,3,4
trace("---") ;
inserted = [1, 2, 3, 4] ;
container = [5, 6, 7, 8] ;
Arrays.spliceInto( inserted, container, 0 , 2 ) ;
trace( "Arrays.spliceInto( inserted, container, 0 , 4 ) : " + container ) ; // 1,2,3,4,7,8