ArrayUtils

Kind of class:public class
Package:com.trycatch.utils
Inherits from:Object
Author:Denny Mcentire
Classpath:com.trycatch.utils.ArrayUtils
File last modified:Tuesday, 09 June 2009, 09:13:08
Class description.
@langversion ActionScript 3.0@playerversion Flash 9.0
Since:
  • 07.06.2008

Summary


Constructor
Class methods

Constructor

ArrayUtils

public function ArrayUtils (
)

ActionScript 3 provides no protection against accidental instantiation of more than
one instance as the constructor has to be public.
@constructor

Class methods

deDupe

public static function deDupe (
arr:Array, prop:String = null) : Array

Parameters:
arr :
Array. To be de-duped.
prop:
String = undefined. Optional property
public:
  • deDupe Returns a Array with duplicates removed.
    Pass an optional property that will be used to evaluate duplicates (can drill down to nested properties eg. "data.src").
    Example: Passing in ["hello", "denny", "nope", "denny", "moth", "hello"] would return ["hello", "denny", "nope", "moth"].
Returns:
  • Array.

filterNotInPropStringMulti

public static function filterNotInPropStringMulti (
arr:Array, props:String, excludes:String) : Array

Parameters:
arr :
Array.
props :
String.
excludes:
String.
public:
  • filterNotInPropStringMulti Returns an Array with properties matching an excludes value filtered out.
    The difference between this and mapNotPropStringMulti is that this one is for an Array property,
    and it checks to see if the value is equal to an item within the array.
Returns:
  • void.

filterNotProp

public static function filterNotProp (
arr:Array, prop:String, val:*) : Array

Parameters:
arr :
Array.
prop:
String.
val :
.
public:
  • filterNotProp Returns an Array of objects that have been filtered on a property for matches to !val
Returns:
  • Array.

filterProp

public static function filterProp (
arr:Array, prop:String, val:*) : Array

Parameters:
arr :
Array.
prop:
String.
val :
.
public:
  • filterProp Returns an Array of objects that have been filtered on a property for matches to val
Returns:
  • Array.

filterPropStringMulti

public static function filterPropStringMulti (
arr:Array, props:String, find:String) : Array

Parameters:
arr :
Array.
props :
String.
excludes:
String.
public:
  • filterPropStringMulti Returns an Array with properties matching a value.
Returns:
  • void.

getInstance

public static function getInstance (

mapNotInPropStringMulti

public static function mapNotInPropStringMulti (
arr:Array, props:String, excludes:String) : Array

Parameters:
arr :
Array.
props :
String.
excludes:
String.
public:
  • mapNotInPropStringMulti Returns an Array with properties matching an excludes value filtered out.
    The difference between this and mapNotPropStringMulti is that this one is for an Array property,
    and it checks to see if the value is equal to an item within the array.
Returns:
  • void.

mapNotPropStringMulti

public static function mapNotPropStringMulti (
arr:Array, props:String, excludes:String) : Array

Parameters:
arr :
Array.
props :
String.
excludes:
String.
public:
  • mapNotPropStringMulti Returns an array with properties matching an excludes value filtered out.
    Example: arr = [{id:"hello"},{id:"nope"},{id:"me"}] props = "id" excludes="hello,nope"
    Would return [{id:"me"}].
Returns:
  • void.

mapProp

public static function mapProp (
arr:Array, prop:String) : Array

Parameters:
arr :
Array.
prop:
String.
public:
  • mapProp Returns the values of the property in each object contained in the array within a new Array.
    This supports drilling down to nested properties.
Returns:
  • Array.

mapPropString

public static function mapPropString (
arr:Array, prop:String) : Array

Parameters:
arr :
Array.
prop:
String.
public:
  • mapPropString Returns the string values of the property in each object contained in the array within a new Array
Returns:
  • Array.

propIn

public static function propIn (
arr:Array, prop:String, val:*) : Boolean

Parameters:
arr :
Array.
prop:
String. Property identifyer.
val :
. Property value to search for.
public:
  • propIn Returns a Boolean of whether an object contained within the array contains a property with a value matching val.
Returns:
  • Boolean.

shuffle

public static function shuffle (
arr:Array, limit:int = undefined) : Array

Parameters:
arr :
Array.
limit:
int. Optional argument that allows you to randomly select a sub-set of the array.
public:
  • shuffle Returns an Array that has hadd the contents randomly shuffled
Returns:
  • Array.

sortOn

public static function sortOn (
arr:Array, prop:String, direction:Number = undefined) : Array

Parameters:
arr :
Array.
prop :
String.
direction:
String = "descending".
public:
  • sortOn Returns a n Array that has been sorted on a property of a nested object.
    The difference between this array and the native sortOn is that you can sort based on a property of a property recursively.
Returns:
  • Array.

swapElements

public static function swapElements (
arr:Array, _elementA:int, _elementB:int) : Array

Parameters:
arr :
The Array to swap elements of.
_elementA:
The element to swap with _elementB.
_elementB:
The element to swap with _elementA.
Returns:
  • The supplied Array with the requested elements swapped.
Example:
  • How To:
    1. Swap two Array elements
    var _myArray:Array = new Array("element1","element2","element3");
    _myArray = ArrayUtils.swapElements(_myArray,1,0); // swap element 1 and element 0
    trace(_myArray); // traces "element2","element1","element3"

vacateElements

public static function vacateElements (
arr:Array, occupyDest:int, occupyAmount:int = 1) : Array

Vacates requested Array elements without destroying their occupants.
Similar to how addChildAt() handles occupied depths.
Parameters:
arr :
The Array to modify.
occupyDest :
The element(s) to make vacant.
occupyAmount:
The number of elements to make room for. Default value is 1.
Returns:
  • The modified Array .
Example:
  • How To:
    • Make room for Array element occupants
    var _exampleArray:Array = new Array("element1", "element2", "element3"); 
    trace(_exampleArray); // traces element1,element2,element3
    _exampleArray = ArrayUtils.vacateElements(_exampleArray,1,3);
    trace(_exampleArray); // element1,,,,element2,element3
    // elements 1,2,3 are now vacant
See also: