/**
 * Title: Array Extensions
 * Date Created: 2006/04/03
 * Description: Extensions to the Array object.
 * Dependencies: 
 * Amendment History:
 * Copyright (c) 2004
 * Company: Azeus Systems Philippines Inc.
 * @author Daniw
 */
 
/**
 * Executes a given function for all the elements of the array.
 */
Array.prototype.forAllDo = function(aFunction) {
  for (var i = 0; i < this.length; i++)
    aFunction(this[i])
}

/**
 * Returns a new array consisting of the elements of the current array
 * used as input to the given function.
 */
Array.prototype.collect = function(aFunction) {
  var result = new Array()
  for (var i = 0; i < this.length; i++)
    result[i] = aFunction(this[i])
  return result
}

/**
 * Returns a new array consisting only of the elements in the current array
 * that caused the given function to return true.
 */
Array.prototype.filter = function(aFunction) {
  var result = new Array()
  for (var i = 0; i < this.length; i++)
    if (aFunction(this[i]))
      result.push(this[i])
  return result
}

/**
 * Checks equality with given array.
 */
Array.prototype.equals = function(anArray) {
  if (anArray == null)
    return false
  if (this.length != anArray.length)
    return false
  for (var i = 0; i < this.length; i++)
    if (this[i] != anArray[i])
      return false
  return true
}

/**
 * Creates an array with range of integers from aBegin to aEnd.
 */
Array.range = function(aBegin, aEnd) {
  var result = new Array()
  for (var i = aBegin; i <= aEnd; i++)
    result.push(i)
  return result
}
