Array.every
static
boolean
Array.every
(
a
,
f
,
o
)
Executes the supplied function on each item in the array.
Iteration stops if the supplied function does not return
a truthy value.
- Parameters:
-
a <Array>
the array to iterate -
f <Function>
the function to execute on each item -
o <object>
Optional context object
- Returns:
boolean
- true if every item in the array returns true from the supplied function.
Array.filter
static
Array
Array.filter
(
a
,
f
,
o
)
Executes the supplied function on each item in the array.
Returns a new array containing the items that the supplied
function returned true for.
- Parameters:
-
a <Array>
the array to iterate -
f <Function>
the function to execute on each item -
o <object>
Optional context object
- Returns:
Array
- The items on which the supplied function returned true. If no items matched an empty array is returned.
Array.find
static
object
Array.find
(
a
,
f
,
o
)
Executes the supplied function on each item in the array,
searching for the first item that matches the supplied
function.
- Parameters:
-
a <Array>
the array to search -
f <Function>
the function to execute on each item. Iteration is stopped as soon as this function returns true on an item. -
o <object>
Optional context object
- Returns:
object
- the first item that the supplied function returns true for, or null if it never returns true
Array.grep
static
Array
Array.grep
(
a
,
pattern
)
Iterates over an array, returning a new array of all the elements
that match the supplied regular expression
- Parameters:
-
a <Array>
a collection to iterate over -
pattern <RegExp>
The regular expression to test against each item
- Returns:
Array
- All the items in the collection that produce a match against the supplied regular expression. If no items match, an empty array is returned.
Array.lastIndexOf
static
int
Array.lastIndexOf
(
a
,
val
)
Returns the index of the last item in the array
that contains the specified value, -1 if the
value isn't found.
- Parameters:
-
a <Array>
the array to search -
val <object>
the value to search for
- Returns:
int
- the index of hte item that contains the value or -1
Array.map
static
Array
Array.map
(
a
,
f
,
o
)
Executes the supplied function on each item in the array.
- Parameters:
-
a <Array>
the array to iterate -
f <Function>
the function to execute on each item -
o <object>
Optional context object
- Returns:
Array
- A new array containing the return value of the supplied function for each item in the original array.
Array.partition
static
Array.partition
(
a
,
o
)
Partitions an array into two new arrays, one with the items
that match the supplied function, and one with the items that
do not.
- Parameters:
-
a <Array>
a collection to iterate over -
o <object>
Optional execution context of f.
- Returns:
- An object with two members, 'matches' and 'rejects', that are arrays containing the items that were selected or rejected by the test function (or an empty array).
Array.reduce
static
Array.reduce
(
a
,
init
,
f
,
o
)
Executes the supplied function on each item in the array.
Reduce "folds" the array into a single value. The callback
function receives four arguments:
the value from the previous callback call (or the initial value),
the value of the current element, the current index, and
the array over which iteration is occurring.
- Parameters:
-
a <Array>
the array to iterate -
init <object>
The initial value to start from -
f <Function>
the function to execute on each item. It is responsible for returning the updated value of the computation. -
o <object>
Optional context object
- Returns:
- A value that results from iteratively applying the supplied function to each element in the array.
Array.reject
static
Array
Array.reject
(
a
,
f
,
o
)
The inverse of filter. Executes the supplied function on each item.
Returns a new array containing the items that the supplied
function returned *false* for.
- Parameters:
-
a <Array>
the array to iterate -
f <Function>
the function to execute on each item -
o <object>
Optional context object
- Returns:
Array
- The items on which the supplied function returned false.
Array.unique
static
Array
Array.unique
(
a
,
sort
)
Returns a copy of the array with the duplicate entries removed
- Parameters:
-
a <Array>
the array to find the subset of uniques for -
sort <bool>
flag to denote if the array is sorted or not. Defaults to false, the more general operation
- Returns:
Array
- a copy of the array with duplicate entries removed
Array.zip
static
Array.zip
(
a
,
a2
)
Creates an array of arrays by pairing the corresponding
elements of two arrays together into a new array.
- Parameters:
-
a <Array>
a collection to iterate over -
a2 <Array>
another collection whose members will be paired with members of the first parameter
- Returns:
- An array of arrays formed by pairing each element of the first collection with an item in the second collection having the corresponding index.