Shared
lib.array
A table used as a prototype for the Array class. Functions can be used as class methods or standard functions.
lib.array:new
Constructs instance of Array containing the given elements.
- ...:
any
lib.array:new(...)
Returns:
- arr:
Array
lib.array.from
Creates a new array from an iterable value.
- iter:
function
|table
|string
- Iterator functions such as string.gmatch can be used to construct arrays.
lib.array.from(iter)
Returns:
- arr:
Array
lib.array.at
Returns the element at the given index, with negative numbers counting backwards from the end of the array.
- index:
integer
lib.array.at(index)
Returns:
- element:
unknown
lib.array.merge
Combines the elements of two or more arrays into a new array.
- ...:
Array
lib.array.merge(...)
Returns:
- Array
lib.array.every
Tests if all elements in an array succeed in passing the provided test function.
- arr:
Array
- testFn:
function(element: unknown): boolean
lib.array.every(arr, testFn)
Returns:
- success:
boolean
lib.array.fill
Sets all elements within a range to the given value and returns the modified array.
- arr:
Array
- value:
any
- start?:
integer
- endIndex?:
integer
lib.array.fill(arr, value, start, endIndex)
Returns:
- arr:
Array
lib.array.filter
Creates a new array containing the elements from an array that pass the provided test function.
- arr:
Array
- testFn:
function(element: unknown): boolean
lib.array.filter(arr, testFn)
Returns:
- newArr:
Array
lib.array.find
Returns the first element of an array the passes the provided test function.
- arr:
Array
- testFn:
function(element: unknown): boolean
- reverse?:
boolean
- Iterate over the array in reverse order.
lib.array.find(arr, testFn, reverse)
Returns:
- element:
unknown
lib.array.findIndex
Returns the index of the first element of an array the passes the provided test function.
- arr:
Array
- testFn:
function(element: unknown): boolean
- reverse?:
boolean
- Iterate over the array in reverse order.
lib.array.findIndex(arr, testFn, reverse)
Returns:
- index:
integer
lib.array.indexOf
Returns the index of the first element of an array the matches the provided value.
- arr:
Array
- value:
any
- reverse?:
boolean
- Iterate over the array in reverse order.
lib.array.indexOf(arr, value, reverse)
Returns:
- index:
integer
lib.array.forEach
Executes the provided function for each element in an array.
- arr:
Array
- cb:
function(element: unknown)
lib.array.forEach(arr, cb, reverse)
Returns:
- index:
integer
lib.array.join
Concatenates all elements of an array into a string, separated by commas or the specified seperator.
- arr:
Array
- seperator?:
string
lib.array.join(arr, seperator)
Returns:
- str:
string
lib.array.map
Create a new array containing the results from calling the provided function on each element in an array.
- fn:
function(element: unknown, index: integer, arr: Array): unknown
lib.array.map(arr, fn)
Returns:
- newArr:
Array
lib.array.pop
Removes the last element from an array and returns the value.
- arr:
Array
lib.array.pop(arr)
Returns:
- element:
unknown
lib.array.push
Adds the given elements to the end of an array and returns the new array length.
- arr:
Array
- ...:
any
lib.array.push(arr, ...)
Returns:
- length:
integer
lib.array.shift
Removes the first element from an array and returns the value.
- arr:
Array
lib.array.shift(arr)
Returns:
- element:
unknown
lib.array.slice
Creates a shallow copy of a portion of an array as a new array.
- arr:
Array
- start?:
integer
- finish?:
integer
lib.array.slice(arr, start, finish)
Returns:
- newArr:
Array
lib.array.toReversed
Creates a new array with the order of its elements reversed from the given array.
- arr:
Array
lib.array.toReversed(arr)
Returns:
- newArr:
Array
lib.array.unshift
Inserts new elements at the start of an array and returns the new array length.
- arr:
Array
- ...:
any
lib.array.unshift(arr, ...)
Returns:
- length:
integer
lib.array.reduce
The "reducer" function is applied to every element in an array, with the previous result serving as the accumulator.
If an initial value is provided it's used as the accumulator for the first index; otherwise iteration starts at the second index, with the first index as the accumulator.
- arr:
Array
- reducer:
function(accumulator: unknown, element: unknown, index?: integer)
- initialValue?:
any
lib.array.reduce(arr, reducer)
Returns:
- accumulator:
unknown
lib.array.reverse
Reverses the order of elements inside an array.
- arr:
Array
lib.array.reverse(arr)
Returns:
- arr:
Array
lib.isArray
Determines if the given table is an instance of Array or an array-like table.
- tbl:
table
lib.array.isArray(tbl)
Returns:
- isArray:
boolean