Class com.bumpslide.util.ArrayUtil

com.bumpslide.util.ArrayUtil

Description

David's handy Array utility methods You can never have enough deep copy implementations

Method Index

average(), dCopy(), findObject(), in_array(), indexOf(), lastIndexOf(), shuffle(), sum()

Method Detail

in_array

static function in_array(needle, haystack:Array)

Checks for the existence of a value in an array concept borrowed from php's in_array function

Parameters

needle
haystack

shuffle

static function shuffle(a:Array)

Shuffles (modifies original) array for card games and such :)

Parameters

aarray to shuffle

findObject

static function findObject(arrayOfObjects:Array, propToSearch:String, valueToFind)

Array search utility Soes something like... SELECT * FROM arrayOfObjects WHERE propToSearch = valueToFind Note: If you are using this, you might be better off with a lookup table or XPath.

Parameters

arrayOfObjects
propToSearchstring name of property to query
valueToFind

dCopy

static function dCopy(obj)

Recursively copies (deep copies) an array or an object There are no recursion limit checks here. Use at your own risk. ObjecUtil.clone is an alias of this method.

Parameters

obj

indexOf

static public function indexOf(array:Array, object):Number

Returns the index of first occurance of the given object within the passed-in array.

The content of the array is searched through by iterating through the array. This method returns the first occurence of the passed-in object within the array. If the object could not be found -1 will be returned. Blatantly stolen from AS2LIB

Parameters

arraythe array to search through
objectthe object to return the position of

Return

the position of the object within the array or -1

lastIndexOf

static public function lastIndexOf(array:Array, object):Number

Returns the index of the last occurance of the given object within the passed-in array. The content of the array is searched through by iterating through the array. This method returns the last occurence of the passed-in object within the array. If the object could not be found -1 will be returned. Blatantly stolen from AS2LIB

Parameters

arraythe array to search through
objectthe object to return the position of

Return

the position of the object within the array or -1

sum

static public function sum(a:Array)

Returns sum of values in an array

Parameters

a

average

static public function average(a:Array)

returns mean of values in an array

Parameters

a