Values
Contains
a.Contains(b) -> boolean
Returns true
if the a
contains the given b
.
- If
a
is an array, returns true ifb
is an element of the array. - If
a
is a map, returns true ifb
is a value in the map. - If
a
is a range, returns true ifb
is a number within the range. - If
a
is a category, returns true ifb
is a subset or equal toa
. - If
a
is a flag, returns true ifb
is a subset or equal toa
. - If
a
is a string, returns true ifb
is a substring ofa
.
In all other cases, returns false.
CountBits
CountBits(x) -> number
Returns the number of bits set in the input.
The input must be a Flag,
unless it is nullish, in which case this function returns undefined
.
IsEmpty
IsEmpty(x) -> boolean
Returns true
if the value is empty, false
otherwise.
A value is empty if it is:
null
orundefined
false
0
@(0,0)
- a String of length 0
- an Array, Map or Range with no elements
Length
Length(x) -> value
Returns the length of x
.
- If
x
is a V2, returns the length of the vector. - If
x
is an array, returns the number of elements. - If
x
is a map, returns the number of key-value pairs. - If
x
is a string, returns the number of characters. Note that this requires iterating through the string as characters are stored as UTF-8. - Otherwise, returns
undefined
.
OrDefault
x.OrDefault(default) -> value
Returns the first argument if it is not undefined
, otherwise returns the second argument.
Overlaps
a.Overlaps(b) -> boolean
Returns true
if the a
and b
have any elements in common.
- If
a
is a category andb
is a category, returns true if they have any categories in common. - If
a
is a flag andb
is a flag, returns true if they have any values in common. - Otherwise, returns false.
Slice
Slice(collection, from, length?) -> array
Returns a new array containing only the elements of the collection
from from
to from + length
.
Returns undefined
if the input is nullish.
Parameters:
collection
(Array): The collection to slice. Currently only Arrays are supported.from
(Number): The index to start slicing from. If negative, counts from the end of the array.length
(Number): The number of elements to include in the slice. If not provided, includes all elements fromfrom
to the end of the array.
Returns: A new array containing the sliced elements.