Source code

CERNY.js.Array

Some useful methods for the Array prototype.

Uses

None

Functions

append

Append array to this array.

array (null,undefined,Array) : the array to append
contains

Figure out whether item is contained in this array.

item (any) : the item to look for in this array
cmpFunc (undefined,function) : the function to use to decide on identity
return (boolean) : true if x is in this array, false otherwise
copy

Copy this array.

return (Array) : a copy of this array
equals

Figure out whether two arrays are equal based on cmpFunc. Order is significant.

array (Array) : the array to compare this array with
cmpFunc (undefined,function) : the function to use to decide on identity
return (boolean) : true, if this array is equal to to array, otherwise false
filter

Filter this array through predicate.

predicate (function) : the predicate to apply to all items of array
return (Array) : a new array containing all items that return true on application of predicate
getInsertionIndex

Gets the insertion index of an item into this array, depending on the passed comperator.

item - the item to insert comperator - the comperator to use for compare items with

indexOf

Figure out the index of item in array based on cmpFunc.

item (any) : the item to look for in this array
cmpFunc (undefined,function) : the function to use to decide on identity
return (number) : the index of the position of item in this array or -1, if item is not in this array.
insertAt

Insert an item at a certain position in the array.

index (number) : the index of the position to insert the item at
item (any) : the item to insert
isSubArray

Figure out whether array is a sub array of this array based on cmpFunc. Order is insignificant.

array (Array) : the array that is checked whether it's a sub array
cmpFunc (undefined,function) : the function to use to decide on identity
return (boolean) : true, if there is no item in array that is not in this array, false otherwise
map

Map an array onto another array based on func.

func (function) : the function that should be applied to all elements of this array
return (Array) : an array of the results of the applications of func to the items of this array
remove

Remove item from this array.

item (any) : the item to remove
cmpFunc (undefined,function) : the function to use to decide on identity
return (number) : the index of the position the item was located
replace

Replace an item in an array.

replaced (any) : the item to be replaced
replacing (any) : the item to take the position of the replaced
cmpFunc (undefined,function) : the function to use to decide on identity
sortedInsert

Performs an insert of an item into this array, depending on the comperator.

item (any) : the item to insert
comperator (function) : the comperator to use for compare items with

History

2007-12-08 : Fixed boundaries bug in insertAt.
2007-11-20 : Removed the check for function of parameter cmpFunc in indexOf.
2007-08-16 : Removed returns the index of the item that is removed.
2007-08-14 : Added sortedInsert.
2007-08-10 : Added insertAt.
2007-06-27 : Added equals.
2007-06-19 : Corrected signature of contains.
2007-05-17 : Using short names for method and signature.
2007-05-09 : Modified append to accept null and undefined.
2007-05-03 : Refactored.
2007-03-15 : Added signatures.
2007-01-06 : Added interception.
2006-12-09 : Fixed bug in contains.
2006-12-08 : Fixed bug in append.
2006-07-26 : Created.

API Documentation for version

2.0

Scripts