Collections
All
collection.All -> boolean
Returns true
if all elements in the collection are truthy, otherwise false.
If the collection is empty, returns true.
If given a value that is not an array or map, returns whether the value is truthy.
Any
collection.Any -> boolean
Returns true
if any elements in the collection are truthy, otherwise false.
If the collection is empty, returns false.
If given a value that is not an array or map, returns whether the value is truthy.
Clear
collection.Clear -> collection
Removes all elements from a collection. If given a value that is not an array or map, returns the original value unchanged.
Filter
collection.Filter |element| { } -> array
Returns a new array containing all elements of the collection for which the predicate returns true.
If the collection is empty, returns an empty array.
If collection
is not an array
, map
or range
, returns undefined.
FindMax
collection.FindMax -> number
Returns the largest element in the collection, ignoring null
and undefined
values.
If the collection is empty, returns undefined.
If collection
is not an array or map, returns the original value unchanged.
FindMin
collection.FindMin -> number
Returns the smallest element in the collection, ignoring null
and undefined
values.
If the collection is empty, returns undefined.
If collection
is not an array or map, returns the original value unchanged.
Map
collection.Map |element| { } -> array
Returns a new array containing the results of applying the selector to each element of the collection.
If collection
is not an array
, map
or range
, returns undefined.
MapKeys
map.MapKeys -> keys
Returns a view of the keys of the given map
.
This can be used in most situations where an array is expected,
for example in a for
loop.
If given a value that is not a map
, returns undefined
.
MapValues
map.MapValues -> values
Returns a view of the values of the given map
.
This can be used in most situations where an array is expected,
for example in a for
loop.
If given a value that is not a map
, returns undefined
.
MaxBy
collection.MaxBy |element| { } -> value
Returns the maximum value in an array, using the result of the selector
function.
The selector
is a function that takes an element of the collection and returns a value.
The selector
is called for each element of the collection.
If collection
is nullish, returns undefined
.
MinBy
collection.MinBy |element| { } -> value
Returns the minimum value in an array, using the result of the selector
function.
The selector
is a function that takes an element of the collection and returns a value.
The selector
is called for each element of the collection.
If selector
returns undefined
for any element, that element is skipped.
If collection
is nullish, returns undefined
.
OrderBy
collection.OrderBy |element| { } -> array
Sorts the elements of an array in ascending order, returning a new sorted array and leaving the original unchanged.
The selector
is a function that takes an element of the collection and returns a value to sort by.
The selector
is called for each element of the collection.
If collection
is nullish, returns undefined
.
OrderByDesc
collection.OrderByDesc |element| { } -> array
Sorts the elements of an array in descending order, returning a new sorted array and leaving the original unchanged.
The selector
is a function that takes an element of the collection and returns a value to sort by.
The selector
is called for each element of the collection.
If collection
is nullish, returns undefined
.
PickRandom
this?.PickRandom(collection) -> element
Returns a random element from the given collection.
this
(Entity): Determine's which entity's random number generator to use. If nullish, usesWorld
. This is optional and is only used to help increase stability if a network rollback occurs.collection
(Array, Map, or Range): The collection to pick from. If nullish, returnsundefined
.
Pop
collection.Pop -> element
Removes the last element from a collection and returns it. If the collection is empty, returns undefined.
If collection
is an array, the last element is removed and returned.
If collection
is a map, the last key-value pair is removed and returned as an array.
Otherwise, does nothing and returns undefined
.
Push
collection.Push(value) -> collection
Adds an element to the end of a collection and returns the modified collection.
- If
collection
is an array,value
is added as a new element. - If
collection
is a map,value
is expected to be an array of key-value pairs, and each pair is added to the map. Or ifvalue
is another map, all entries are added to thecollection
map. - Otherwise, returns the original
collection
unchanged.
Range
Range(from, to) -> range
Returns a range representing all integers between from
and to
(exclusive).
If to
is less than or equal to from
, returns an empty range.
RangeInclusive
RangeInclusive(from, to) -> range
Returns a range
representing all integers from from
to to
(inclusive).
If to
is less than from
, returns an empty range.
Shuffle
this?.Shuffle(array) -> array
Shuffles an array in place. Returns the shuffled array.
this
(Entity): Determine's which entity's random number generator to use. If nullish, usesWorld
. This is optional and is only used to help increase stability if a network rollback occurs.array
(Array): The array to shuffle. If nullish, returnsundefined
.
Sort
collection.Sort -> collection
Sorts the elements of an array in ascending order.
The array is modified in place.
It is returned to allow for chaining.
If the collection
is not an array, it is returned unchanged.
SortDesc
SortDesc(collection) -> collection
Sorts the elements of an array in descending order.
The array is modified in place.
It is returned to allow for chaining.
If the collection
is not an array, it is returned unchanged.
Sum
collection.Sum -> number
Returns the sum of all numbers in the collection.
All non-number elements are ignored.
If the collection is empty, returns 0.
If collection
is not a collection, returns the original value if it is a number, otherwise returns 0.
VectorSum
collection.VectorSum -> vector
Returns the sum of all Vector elements in the collection.
All non-Vector elements are ignored.
If the collection is empty, returns @(0,0)
.
If collection
is not a collection, returns the original value if it is a Vector, otherwise returns @(0,0)
.