Array
Last updated
Last updated
These are extensions to JavaScript's Array. . All of the methods that Rulecube has added return an array leave the original array intact and return a new array.
Filters based on the given predicate and returns the filtered array. Essentially an alias for .
Parameters
predicate function
Predicate function for filtering data. This function is called with 3 parameters: value, index and the array itself.
Return type
array
Examples
Filters the collection based cross-checking every item using the predicate, with another list. Also known as an Intersect.
Parameters
predicate function
(optional) Predicate for selecting the data. This function is called with 3 parameters: value, index and the array itself.
otherList array
The other list to compare with.
Return type
array
Examples
This is the inverse operation of the whereIn. Also known as an Except.
Parameters
predicate function
(optional) Predicate for selecting the data. This function is called with 3 parameters: value, index and the array itself.
otherList array
The other list to compare with.
Return type
array
Examples
Filters based on the given type and returns the filtered typed array.
Parameters
type Type
The type to filter by.
Return type
array
Examples
Parameters
predicate function
Predicate for transforming/mapping the data. This function is called with 3 parameters: value, index and the array itself.
Return type
array
Examples
Sorts the collection in an ascending order.
Parameters
predicate function
(optional) Predicate for ordering data. This function is called with 1 parameter: value.
Return type
array
Examples
Sorts the collection in an descending order.
Parameters
predicate function
(optional) Predicate for ordering data. This function is called with 1 parameter: value.
Return type
array
Examples
Parameters
Return type
array
Examples
Parameters
Return type
array
Examples
Parameters
Return type
array
Examples
Reduces the collection to the given amount of items from the start.
Parameters
num number
The number of items to take.
Return type
array
Examples
Reduces the collection by removing the given amount of items.
Parameters
num number
The number of items to skip.
Return type
array
Examples
Reduces the collection to contain only unique values.
Parameters
predicate function
(optional) Predicate for comparing the data.
Return type
array
Examples
Groups the collection based on the given predicate.
Parameters
predicate function
Predicate for grouping the data.
Return type
array
Examples
Groups and maps the collection based on the given predicates.
Parameters
groupPredicate function
Predicate for grouping the data.
mapPredicate function
Predicate for transforming/mapping the data.
Return type
array
Examples
Parameters
predicate function
Predicate for finding the item. This function is called with 3 parameters: value, index and the array itself.
Return type
any
Examples
Returns the item with the lowest-valued numeric value in the collection. A predicate may be used to transform/map the data. Note: This is similar to min() but returns the item instead of the value. See also:
Array.min
Parameters
predicate function
(optional) Predicate for transforming/mapping the data.
Return type
T
Examples
Returns the item with the highest-valued numeric value in the collection. A predicate may be used to transform/map the data. Note: This is similar to max() but returns the item instead of the value. See also:
Array.max
Parameters
predicate function
(optional) Predicate for transforming/mapping data.
Return type
T
Examples
Returns the first item in the collection. When given a predicate, finds and returns the first item that matches, similar to find().
Parameters
predicate function
(optional) Predicate for finding the item. When not provided, this method will return the first item in the collection.
Return type
T
Examples
Returns the last item in the collection. When given a predicate, finds and returns the last item that matches.
Parameters
predicate function
(optional) Predicate for finding the item. When not provided, this method will return the last item in the collection.
Return type
T
Examples
Computes the sum of the collection based on the given predicate.
Parameters
predicate function
(optional) Predicate for selecting data.
Return type
number
Examples
Returns the lowest-valued numeric value in the collection. A predicate may be used to transform/map the data. See also:
Array.findMin
Parameters
predicate function
(optional) Predicate for transforming/mapping the data.
Return type
number
Examples
Returns the highest-valued numeric value in the collection. A predicate may be used to transform/map the data. See also:
Array.findMax
Parameters
predicate function
(optional) Predicate for transforming/mapping data.
Return type
number
Examples
Computes the average value of the collection based on the given predicate.
Parameters
predicate function
(optional) Predicate for selecting data.
Return type
number
Examples
Parameters
predicate function
(optional) Predicate function for evaluating data. This function is called with 3 parameters: value, index and the array itself.
Return type
boolean
Examples
Parameters
predicate function
(optional) Predicate for matching data.
Return type
boolean
Examples
Returns whether none of the items in the collection matches the given predicate. The inverse of any().
Parameters
predicate function
(optional) Predicate function for evaluating data. This function is called with 3 parameters: value, index and the array itself.
Return type
boolean
Examples
Parameters
item any
The item to look for in the collection.
Return type
number
Examples
Filters the collection based on the given predicate and returns the number of items left.
Parameters
predicate function
(optional) Predicate for filtering data.
Return type
number
Examples
Casts collection to a different type. Has no effect during run-time, but helps with autocompletion.
Parameters
otherType any
Type to cast to.
Return type
array
Examples
Transforms the collection based on the given predicate. Actually one of the Array standard methods, but included here for reference. See also: .
Create a (shallow) copy of the collection.
Note: functions the same as .
.
Reverses the collection. Actually one of the Array standard methods, but included here for reference. See also: .
Note: this changes the order of the array and does not create a copy! Use .copy().reverse()
or .reverseCopy()
for that instead.
Reverses a copy of the collection, leaves the original intact. Note: This is different from the native: .
Finds an item in the collection based on the given predicate and returns the first item that matches. Actually one of the Array standard methods, but included here for reference. See also: .
Returns whether any item in the collection matches the given predicate. Essentially an alias for .
Returns whether every item in the collection matches the given predicate. Essentially an alias for .
Returns whether the given item is included in the collection. Essentially an alias for .