array
Functions
from
array.from(T values) → array<T>This function 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(int size = 0, T initial_value = na) → const array<T>This function 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(int size = 0, bool initial_value = false) → const array<bool>This function creates a new empty array of type bool.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | The initial size of the array. |
initial_value | bool | false | The initial value for all elements. |
Returns: const array<bool>
new_box
array.new_box(int size = 0, box initial_value = na) → const array<box>This function creates a new empty array of type box.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | The initial size of the array. |
initial_value | box | na | The initial value for all elements. |
Returns: const array<box>
new_color
array.new_color(int size = 0, color initial_value = na) → const array<color>This function creates a new empty array of type color.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | The initial size of the array. |
initial_value | color | na | The initial value for all elements. |
Returns: const array<color>
new_float
array.new_float(int size = 0, float initial_value = na) → const array<float>This function creates a new empty array of type float.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | The initial size of the array. |
initial_value | float | na | The initial value for all elements. |
Returns: const array<float>
new_int
array.new_int(int size = 0, int initial_value = na) → const array<int>This function creates a new empty array of type int.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | The initial size of the array. |
initial_value | int | na | The initial value for all elements. |
Returns: const array<int>
new_label
array.new_label(int size = 0, label initial_value = na) → const array<label>This function creates a new empty array of type label.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | The initial size of the array. |
initial_value | label | na | The initial value for all elements. |
Returns: const array<label>
new_line
array.new_line(int size = 0, line initial_value = na) → const array<line>This function creates a new empty array of type line.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | The initial size of the array. |
initial_value | line | na | The initial value for all elements. |
Returns: const array<line>
new_linefill
array.new_linefill(
int size = 0,
linefill initial_value = na
) → const array<linefill>This function creates a new empty array of type linefill.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | The initial size of the array. |
initial_value | linefill | na | The initial value for all elements. |
Returns: const array<linefill>
new_string
array.new_string(int size = 0, string initial_value = na) → const array<string>This function creates a new empty array of type string.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | The initial size of the array. |
initial_value | string | na | The initial value for all elements. |
Returns: const array<string>
new_table
array.new_table(int size = 0, table initial_value = na) → const array<table>This function creates a new empty array of type table.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
size | int | 0 | The initial size of the array. |
initial_value | table | na | The initial value for all elements. |
Returns: const array<table>
Methods
abs
This function returns a new array containing the absolute values of the elements of the input array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<int> | The input array of integer elements. |
Returns: array<int>
avg
This function returns the average of the elements in the input array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | series array<int> | The input array of integer elements. |
Returns: float
binary_search
This function performs a binary search for the specified value in the given sorted array and returns the index of the value if found, or -1 if not found.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | 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
This function returns the index of the value if it is found.
When the value is not found, the function returns the index of the next smallest element to the left of where the value would lie if it was in the array. The array to search must be sorted in ascending order.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<int> | The sorted array of integers to search. | |
value | int | The value to search for. |
Returns: int
binary_search_rightmost
This function returns the index of the value if it is found.
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 |
|---|---|---|---|
array | array<int> | The sorted array of integers to search. | |
value | int | The value to search for. |
Returns: int
clear
array.clear(series array<T> array)This function clears all elements from the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | series array<T> | The array to clear. |
concat
array.concat(array<T> array1, array<T> array2) → array<T>This function concatenates two arrays array1 and array2 of the same type T and returns a new array containing all elements from both arrays.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array1 | array<T> | The first array to concatenate. | |
array2 | array<T> | The second array to concatenate. |
Returns: array<T>
copy
array.copy(array<T> array) → array<T>This function creates a copy of the given array and returns the new array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<T> | The array to copy. |
Returns: array<T>
covariance
This function calculates the covariance between two arrays array1 and array2 of the same type T.
The biased parameter determines whether to use biased or unbiased estimation.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array1 | array<float> | The first input array. | |
array2 | 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
This function 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 |
|---|---|---|---|
array | array<bool> | The array to check. |
Returns: bool
fill
array.fill(array<T> array, T value, int index_from = 0, int index_to = na)This function fills the elements of the given array with the specified value from index_from to index_to.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | 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(array<T> array) → TThis function returns the first element of the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<T> | The array to retrieve the first element from. |
Returns: T
get
array.get(array<T> array, int index) → TThis function returns the element at the specified index from the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<T> | The array to retrieve the element from. | |
index | int | The index of the element to retrieve. |
Returns: T
includes
array.includes(array<T> array, T value) → boolThis function checks 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 |
|---|---|---|---|
array | array<T> | The array to search. | |
value | T | The value to search for. |
Returns: bool
indexof
array.indexof(array<T> array, T value) → intThis function returns 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 |
|---|---|---|---|
array | 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(array<T> array, int index, T value)This function inserts the specified value at the given index in the array, shifting subsequent elements to the right.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<T> | The array to modify. | |
index | int | The index at which to insert the value. | |
value | T | The value to insert. |
join
This function joins the elements of the given array into a single string, with each element separated by the specified separator.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<int> | The array of integers to join. | |
separator | string | The separator string to place between elements. |
Returns: string
last
array.last(array<T> array) → TThis function returns the last element of the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<T> | The array to retrieve the last element from. |
Returns: T
lastindexof
array.lastindexof(array<T> array, T value) → intThis function returns 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 |
|---|---|---|---|
array | 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
This function returns the nth maximum value from the given array.
The nth parameter specifies which maximum to return (0 for the largest, 1 for the second largest, etc.).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | 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
This function returns the median value of the elements in the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<int> | The input array of integers. |
Returns: float
min
This function returns the nth minimum value from the given array.
The nth parameter specifies which minimum to return (0 for the smallest, 1 for the second smallest, etc.).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | 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 |
|---|---|---|---|
array | array<int> | The input array of integers. |
Returns: int — The most frequently occurring value, or the smallest among tied values.
percentile_linear_interpolation
This function returns the value at the specified percentile from the given array using linear interpolation.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<int> | The input array of integers. | |
percentage | float | The percentile value (0-100). |
Returns: float
percentile_nearest_rank
This function returns the value at the specified percentile from the given array using the nearest-rank method.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<int> | The input array of integers. | |
percentage | float | The percentile value (0-100). |
Returns: float
percentrank
This function returns the percentile rank of the element at the specified index in the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | 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.
pop
array.pop(array<T> array) → TThis function removes and returns the last element from the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<T> | The array from which to pop an element. |
Returns: T
push
array.push(array<T> array, T value)This function appends the given value to the end of the array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<T> | The array to which the value will be appended. | |
value | T | The value to append to the array. |
range
This function returns the range (difference between the maximum and minimum values) of the elements in the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<int> | The input array of integers. |
Returns: int
remove
array.remove(array<T> array, int index) → TThis function removes the element at the specified index from the given array and returns the removed element.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<T> | The array to modify. | |
index | int | The index of the element to remove. |
Returns: T
reverse
array.reverse(array<T> array)This function reverses the order of elements in the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<T> | The array to reverse. |
set
array.set(array<T> array, int index, T value)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 |
|---|---|---|---|
array | 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(array<T> array) → TThis function removes and returns the first element from the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<T> | The array from which to shift an element. |
Returns: T
size
array.size(array<T> array) → intThis function returns the size (number of elements) of the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<T> | The array whose size is to be determined. |
Returns: int
slice
array.slice(array<T> array, int index_from = 0, int index_to = na) → array<T>This function creates a new array that is a slice of the given array, starting from index_from to index_to.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | 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
This function checks if at least one element in the given boolean array is true.
It returns true if any element is true, and false otherwise.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<bool> | The array to check. |
Returns: bool
sort
This function sorts the elements of the given array in ascending or descending order.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<int> | The array of integers to sort. | |
order | any | order.ascending | The sort order. |
sort_indices
This function returns an array of indices that would sort the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<int> | The array of integers to analyze. | |
order | any | order.ascending | The sort order. |
Returns: array<int> — An array of original indices rearranged so that array.get(result.get(i)) yields the i-th sorted element.
standardize
This function standardizes the elements of the given array by subtracting the mean and dividing by the standard deviation.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<float> | The input array of floats. |
Returns: array<float> — A new array where each element is (value - mean) / stdev (z-scores).
stdev
This function calculates the standard deviation of the elements in the given array.
The biased parameter determines whether to use biased or unbiased estimation.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | 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
This function calculates the sum of the elements in the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<int> | The input array of integers. |
Returns: int
unshift
array.unshift(array<T> array, T value)This function adds the specified value to the beginning of the given array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | array<T> | The array to modify. | |
value | T | The value to add to the beginning. |
variance
This function calculates the variance of the elements in the given array.
The biased parameter determines whether to use biased or unbiased estimation.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
array | 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