ArrayUtil
| Kind of class: | class |
|---|---|
| Inherits from: | none |
| Version: | 12/12/06 |
| Author: | Aaron Clinger, David Nelson |
| Classpath: | org.casaframework.util.ArrayUtil |
| File last modified: | Wednesday, 24 January 2007, 21:45:40 |
Since:
Flash Player 7
Summary
Class methods
average
static function average (
inArray:Array) : Number
Averages the values in
inArray.Parameters:
inArray:
Array comprised only of numbers.
Returns:
The average of all numbers in the
inArray.Usage:
var numberArray:Array = new Array(2, 3, 8, 3); trace("Average is: " + ArrayUtil.average(this.numberArray));
contains
static function contains (
inArray:Array,
item:Object) : Number
Finds if Array contains
item.Parameters:
inArray:
Array to search for
item in.item :
Object to find.
Returns:
The amount of
item's found; if none were found returns 0.Usage:
var numberArray:Array = new Array(1, 2, 3, 7, 7, 7, 4, 5); trace("numberArray contains " + ArrayUtil.contains(this.numberArray, 7) + " 7's.");
Usage note:
If you are trying to find if an array contains an item or not and don't need to know the total, use #indexOf instead.
item can be any object; Number, String, Object, etc...getHighestValue
static function getHighestValue (
inArray:Array) : Number
Finds the highest value in
inArray.Parameters:
inArray:
Array comprised only of numbers.
Returns:
The highest value in
inArray.Usage:
var numberArray:Array = new Array(2, 1, 5, 4, 3); trace("The highest value is: " + ArrayUtil.getHighestValue(this.numberArray));
getLowestValue
static function getLowestValue (
inArray:Array) : Number
Finds the lowest value in
inArray.Parameters:
inArray:
Array comprised only of numbers.
Returns:
The lowest value in
inArray.Usage:
var numberArray:Array = new Array(2, 1, 5, 4, 3); trace("The lowest value is: " + ArrayUtil.getLowestValue(this.numberArray));
indexOf
static function indexOf (
inArray:Array,
item:Object,
startIndex:Number) : Number
Finds the position of the first instance of passed
item in inArray.Parameters:
inArray :
Array to find
item's position in.item :
Object to find position of.
startIndex:
[optional] The starting position of the search.
Returns:
The first position number of the instance
item; if none found returns -1.Usage:
var colorArray = new Array("red", "blue", "pink", "black"); trace("First postion of 'pink' is: " + ArrayUtil.indexOf(this.colorArray, "pink"));
Usage note:
item can be any object; Number, String, Object, etc...randomize
static function randomize (
inArray:Array) : Array
Creates new Array composed of passed Array's items in a random order.
Parameters:
inArray:
Array to create copy of, and randomize.
Returns:
A new Array comprised of passed Array's items in a random order.
Usage:
var numberArray:Array = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); trace(ArrayUtil.randomize(this.numberArray));
removeArrayItem
static function removeArrayItem (
tarArray:Array,
item:Object) : Number
Modifies original Array by removing all items that are identical to passed
item.Parameters:
tarArray:
Array to remove passed
item.item :
Value to remove.
Returns:
The amount of removed elements that matched
item, if none found returns 0.Usage:
var numberArray:Array = new Array(1, 2, 3, 7, 7, 7, 4, 5); trace("Removed " + ArrayUtil.removeArrayItem(this.numberArray, 7) + " items."); trace(this.numberArray);
Usage note:
item can be any object; Number, String, Object, etc...removeDuplicates
static function removeDuplicates (
inArray:Array) : Array
Creates new Array comprised of only the non-identical elements of passed Array.
Parameters:
inArray:
Array to remove equivalent items.
Returns:
A new Array comprised of only unique elements.
Usage:
var numberArray:Array = new Array(1, 2, 3, 4, 4, 4, 4, 5); trace(ArrayUtil.removeDuplicates(this.numberArray));
sum
static function sum (
inArray:Array) : Number
Adds all items in
inArray and returns the value.Parameters:
inArray:
Array comprised only of numbers.
Returns:
The total of all numbers in
inArray added.Usage:
var numberArray:Array = new Array(2, 3); trace("Total is: " + ArrayUtil.sum(this.numberArray));