Array<T>
An ordered, indexable collection of elements of type T.
Create with Array.new() or an array literal [1, 2, 3]. Access elements with get / set; iterate with for v in arr.
Kind: object
Static Methods
from
Array.from(values: T): Array<T>Creates a new array containing the provided values.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
values | T | Variable number of elements to include in the array. |
Returns: Array<T>
new
Array.new(size: int = 0, initial_value: T = na): const Array<T>Creates a new empty array of type T.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | The initial size of the array. |
initial_value | T | na | The initial value for all elements. |
Returns: const Array<T>
new_bool
Array.new_bool(size: int = 0, initial_value: bool = na): Array<bool>Creates a new array of bool values.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | Initial size of the array. Default is 0. |
initial_value | bool | na | Initial value for all elements. Default is na. |
Returns: Array<bool>
new_box
Array.new_box(size: int = 0, initial_value: Box = na): Array<Box>Creates a new array of Box ids.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | Initial size of the array. Default is 0. |
initial_value | Box | na | Initial value for all elements. Default is na. |
new_color
Array.new_color(size: int = 0, initial_value: color = na): Array<color>Creates a new array of color values.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | Initial size of the array. Default is 0. |
initial_value | color | na | Initial value for all elements. Default is na. |
Returns: Array<color>
new_float
Array.new_float(size: int = 0, initial_value: float = na): Array<float>Creates a new array of float values.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | Initial size of the array. Default is 0. |
initial_value | float | na | Initial value for all elements. Default is na. |
Returns: Array<float>
new_int
Array.new_int(size: int = 0, initial_value: int = na): Array<int>Creates a new array of int values.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | Initial size of the array. Default is 0. |
initial_value | int | na | Initial value for all elements. Default is na. |
Returns: Array<int>
new_label
Array.new_label(size: int = 0, initial_value: Label = na): Array<Label>Creates a new array of Label ids.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | Initial size of the array. Default is 0. |
initial_value | Label | na | Initial value for all elements. Default is na. |
new_line
Array.new_line(size: int = 0, initial_value: Line = na): Array<Line>Creates a new array of Line ids.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | Initial size of the array. Default is 0. |
initial_value | Line | na | Initial value for all elements. Default is na. |
new_linefill
Array.new_linefill(size: int = 0, initial_value: Linefill = na): Array<Linefill>Creates a new array of Linefill ids.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | Initial size of the array. Default is 0. |
initial_value | Linefill | na | Initial value for all elements. Default is na. |
new_string
Array.new_string(size: int = 0, initial_value: string = na): Array<string>Creates a new array of string values.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | Initial size of the array. Default is 0. |
initial_value | string | na | Initial value for all elements. Default is na. |
Returns: Array<string>
new_table
Array.new_table(size: int = 0, initial_value: Table = na): Array<Table>Creates a new array of Table ids.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | Initial size of the array. Default is 0. |
initial_value | Table | na | Initial value for all elements. Default is na. |
Methods
abs
Returns a new array containing the absolute values of the elements of the input id.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<int> | the input array of integer elements. |
Returns: Array<int>
avg
Returns the average of the elements in the input id.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | series Array<int> | the input array of integer elements. |
Returns: float
binary_search
Performs a binary search for the specified value in the given sorted id and returns the index of the value if found, or -1 if not found.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<int> | The sorted array of integers to search. | |
value | int | The value to search for. |
Returns: int — The index of the value, or -1 if not found. the array must be sorted in ascending order.
binary_search_leftmost
Returns the index of the matching value in the sorted array.
If the value is not found, the function returns the index of the nearest smaller element to the left of where the value would be inserted. the array to search must be sorted in ascending order.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<int> | The sorted array of integers to search. | |
value | int | The value to search for. |
Returns: int
binary_search_rightmost
Returns the index of the matching value in the sorted array.
When the value is not found, the function returns the index of the element to the right of where the value would lie if it was in the array. the array must be sorted in ascending order.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<int> | The sorted array of integers to search. | |
value | int | The value to search for. |
Returns: int
clear
Array.clear(id: series Array<T>)Clears all elements from the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | series Array<T> | the array to clear. |
concat
Array.concat(id1: Array<T>, id2: Array<T>): Array<T>Concatenates two arrays of the same type T and returns a new array containing all elements from both arrays.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id1 | Array<T> | The first array to concatenate. | |
id2 | Array<T> | The second array to concatenate. |
Returns: Array<T>
copy
Array.copy(id: Array<T>): Array<T>Creates a copy of the given array and returns the new id.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<T> | the array to copy. |
Returns: Array<T>
covariance
Calculates the covariance between two arrays of the same type T.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id1 | Array<float> | The first input array. | |
id2 | Array<float> | The second input array. | |
biased | any | true | If true, the function uses biased estimation (dividing by n); if false, it uses unbiased estimation (dividing by n-1). |
Returns: float
every
Checks if every element in the given boolean array is true.
It returns true if all elements are true, and false otherwise.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<bool> | the array to check. |
Returns: bool
fill
Array.fill(id: Array<T>, value: T, index_from: int = 0, index_to: int = na)Fills the elements of the given array with the specified value from index_from to index_to.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<T> | the array to fill. | |
value | T | The value to fill with. | |
index_from | int | 0 | The starting index (inclusive). |
index_to | int | na | The ending index (exclusive). When na, denotes end of array. |
first
Array.first(id: Array<T>): TReturns the first element of the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<T> | the array to retrieve the first element from. |
Returns: T
get
Array.get(id: Array<T>, index: int): TReturns the element at the specified index from the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<T> | the array to retrieve the element from. | |
index | int | The index of the element to retrieve. |
Returns: T
includes
Array.includes(id: Array<T>, value: T): boolChecks if the given array includes the specified value.
It returns true if the value is found in the array, and false otherwise.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<T> | the array to search. | |
value | T | The value to search for. |
Returns: bool
indexof
Array.indexof(id: Array<T>, value: T): intReturns the index of the first occurrence of the specified value in the given array.
If the value is not found, it returns -1.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<T> | the array to search. | |
value | T | The value to search for. |
Returns: int — The zero-based index of the first occurrence, or -1 if not found.
insert
Array.insert(id: Array<T>, index: int, value: T)Inserts the specified value at the given index in the id, shifting subsequent elements to the right.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<T> | the array to modify. | |
index | int | The index at which to insert the value. | |
value | T | The value to insert. |
join
Joins the elements of the given array into a single string, with each element separated by the specified separator.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<int> | the array of integers to join. | |
separator | string | The separator string to place between elements. |
Returns: string
last
Array.last(id: Array<T>): TReturns the last element of the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<T> | the array to retrieve the last element from. |
Returns: T
lastindexof
Array.lastindexof(id: Array<T>, value: T): intReturns the index of the last occurrence of the specified value in the given array.
If the value is not found, it returns -1.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<T> | the array to search. | |
value | T | The value to search for. |
Returns: int — The zero-based index of the last occurrence, or -1 if not found.
max
Returns the nth maximum value from the given id.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<int> | the input array of integers. | |
nth | int | 0 | Which maximum to return (0 for the largest, 1 for the second largest, etc.). |
Returns: int
median
Returns the median value of the elements in the given id.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<int> | the input array of integers. |
Returns: float
min
Returns the nth minimum value from the given id.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<int> | the input array of integers. | |
nth | int | 0 | Which minimum to return (0 for the smallest, 1 for the second smallest, etc.). |
Returns: int
mode
The function returns the mode of an array's elements.
If there are several values with the same frequency, it returns the smallest value.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<int> | the input array of integers. |
Returns: int — The most frequently occurring value, or the smallest among tied values.
percent_rank
Returns the percentile rank of the element at the specified index in the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<int> | the input array of integers. | |
index | int | The index of the element. |
Returns: float — A value between 0 and 100 indicating the percentage of elements that are less than or equal to the element at index.
percentile_linear_interpolation
Returns the value at the specified percentile from the given array using linear interpolation.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<int> | the input array of integers. | |
percentage | float | The percentile value (0-100). |
Returns: float
percentile_nearest_rank
Returns the value at the specified percentile from the given array using the nearest-rank method.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<int> | the input array of integers. | |
percentage | float | The percentile value (0-100). |
Returns: float
pop
Array.pop(id: Array<T>): TRemoves and returns the last element from the given id.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<T> | the array from which to pop an element. |
Returns: T
push
Array.push(id: Array<T>, value: T)Appends the given value to the end of the array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<T> | the array to which the value will be appended. | |
value | T | The value to append to the array. |
range
Returns the range (difference between the maximum and minimum values) of the elements in the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<int> | the input array of integers. |
Returns: int
remove
Array.remove(id: Array<T>, index: int): TRemoves the element at the specified index from the given array and returns the removed element.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<T> | the array to modify. | |
index | int | The index of the element to remove. |
Returns: T
reverse
Array.reverse(id: Array<T>)Reverses the order of elements in the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<T> | the array to reverse. |
set
Array.set(id: Array<T>, index: int, value: T)Sets the element at the specified index in the array to the provided value.
If the index is positive, the function counts from the beginning of the array (0-based), and if the index is negative, it counts from the end of the array (-1 being the last element). For example, for an array that contains [10, 20, 30], all of the following indexes are valid: 0, 1, 2, -1, -2, -3.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<T> | the array to modify. | |
index | int | The index of the element (supports negative indexing). | |
value | T | The value to set at the specified index. |
shift
Array.shift(id: Array<T>): TRemoves and returns the first element from the given id.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<T> | the array from which to shift an element. |
Returns: T
size
Array.size(id: Array<T>): intReturns the size (number of elements) of the given id.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<T> | the array whose size is to be determined. |
Returns: int
slice
Array.slice(id: Array<T>, index_from: int = 0, index_to: int = na): Array<T>Creates a new array that is a slice of the given id, starting from index_from to index_to.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<T> | the array to slice. | |
index_from | int | 0 | The starting index (inclusive). |
index_to | int | na | The ending index (exclusive). When na, denotes end of array. |
Returns: Array<T>
some
Checks if at least one element in the given boolean id is true.
It returns true if any element is true, and false otherwise.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<bool> | the array to check. |
Returns: bool
sort
Sorts the elements of the given array in ascending or descending order.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<int> | the array of integers to sort. | |
order | any | SortOrder.Ascending | The sort order. |
sort_indices
Returns an array of indices that would sort the given id.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<int> | the array of integers to analyze. | |
order | any | SortOrder.Ascending | The sort order. |
Returns: Array<int> — an array of original indices rearranged so that result.get(i).get() yields the i-th sorted element.
standardize
Standardizes the elements of the given array by subtracting the mean and dividing by the standard deviation.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<float> | the input array of floats. |
Returns: Array<float> — a new array where each element is (value - mean) / stdev (z-scores).
stdev
Calculates the standard deviation of the elements in the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<float> | the input array of floats. | |
biased | any | true | If true, the function uses biased estimation (dividing by n); if false, it uses unbiased estimation (dividing by n-1). |
Returns: float
sum
Calculates the sum of the elements in the given id.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<int> | the input array of integers. |
Returns: int
unshift
Array.unshift(id: Array<T>, value: T)Adds the specified value to the beginning of the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<T> | the array to modify. | |
value | T | The value to add to the beginning. |
variance
Calculates the variance of the elements in the given id.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Array<int> | the input array of integers. | |
biased | any | true | If true, the function uses biased estimation (dividing by n); if false, it uses unbiased estimation (dividing by n-1). |
Returns: float