Skip to content

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

navi
Array.from(values: T): Array<T>

Creates a new array containing the provided values.

Parameters

NameTypeDefaultDescription
valuesTVariable number of elements to include in the array.

Returns: Array<T>


new

navi
Array.new(size: int = 0, initial_value: T = na): const Array<T>

Creates a new empty array of type T.

Parameters

NameTypeDefaultDescription
sizeint0The initial size of the array.
initial_valueTnaThe initial value for all elements.

Returns: const Array<T>


new_bool

navi
Array.new_bool(size: int = 0, initial_value: bool = na): Array<bool>

Creates a new array of bool values.

Parameters

NameTypeDefaultDescription
sizeint0Initial size of the array. Default is 0.
initial_valueboolnaInitial value for all elements. Default is na.

Returns: Array<bool>


new_box

navi
Array.new_box(size: int = 0, initial_value: Box = na): Array<Box>

Creates a new array of Box ids.

Parameters

NameTypeDefaultDescription
sizeint0Initial size of the array. Default is 0.
initial_valueBoxnaInitial value for all elements. Default is na.

Returns: Array<Box>


new_color

navi
Array.new_color(size: int = 0, initial_value: color = na): Array<color>

Creates a new array of color values.

Parameters

NameTypeDefaultDescription
sizeint0Initial size of the array. Default is 0.
initial_valuecolornaInitial value for all elements. Default is na.

Returns: Array<color>


new_float

navi
Array.new_float(size: int = 0, initial_value: float = na): Array<float>

Creates a new array of float values.

Parameters

NameTypeDefaultDescription
sizeint0Initial size of the array. Default is 0.
initial_valuefloatnaInitial value for all elements. Default is na.

Returns: Array<float>


new_int

navi
Array.new_int(size: int = 0, initial_value: int = na): Array<int>

Creates a new array of int values.

Parameters

NameTypeDefaultDescription
sizeint0Initial size of the array. Default is 0.
initial_valueintnaInitial value for all elements. Default is na.

Returns: Array<int>


new_label

navi
Array.new_label(size: int = 0, initial_value: Label = na): Array<Label>

Creates a new array of Label ids.

Parameters

NameTypeDefaultDescription
sizeint0Initial size of the array. Default is 0.
initial_valueLabelnaInitial value for all elements. Default is na.

Returns: Array<Label>


new_line

navi
Array.new_line(size: int = 0, initial_value: Line = na): Array<Line>

Creates a new array of Line ids.

Parameters

NameTypeDefaultDescription
sizeint0Initial size of the array. Default is 0.
initial_valueLinenaInitial value for all elements. Default is na.

Returns: Array<Line>


new_linefill

navi
Array.new_linefill(size: int = 0, initial_value: Linefill = na): Array<Linefill>

Creates a new array of Linefill ids.

Parameters

NameTypeDefaultDescription
sizeint0Initial size of the array. Default is 0.
initial_valueLinefillnaInitial value for all elements. Default is na.

Returns: Array<Linefill>


new_string

navi
Array.new_string(size: int = 0, initial_value: string = na): Array<string>

Creates a new array of string values.

Parameters

NameTypeDefaultDescription
sizeint0Initial size of the array. Default is 0.
initial_valuestringnaInitial value for all elements. Default is na.

Returns: Array<string>


new_table

navi
Array.new_table(size: int = 0, initial_value: Table = na): Array<Table>

Creates a new array of Table ids.

Parameters

NameTypeDefaultDescription
sizeint0Initial size of the array. Default is 0.
initial_valueTablenaInitial value for all elements. Default is na.

Returns: Array<Table>

Methods

abs

Returns a new array containing the absolute values of the elements of the input id.

Parameters

NameTypeDefaultDescription
idArray<int>the input array of integer elements.

Returns: Array<int>

Returns a new array containing the absolute values of the elements of the input id.

Parameters

NameTypeDefaultDescription
idArray<float>the input array of float elements.

Returns: Array<float>


avg

Returns the average of the elements in the input id.

Parameters

NameTypeDefaultDescription
idseries Array<int>the input array of integer elements.

Returns: float

Returns the average.

Parameters

NameTypeDefaultDescription
idseries Array<float>the input array of float elements.

Returns: float


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

NameTypeDefaultDescription
idArray<int>The sorted array of integers to search.
valueintThe value to search for.

Returns: int — The index of the value, or -1 if not found. the array must be sorted in ascending order.

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

NameTypeDefaultDescription
idArray<float>The sorted array of floats to search.
valuefloatThe 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

NameTypeDefaultDescription
idArray<int>The sorted array of integers to search.
valueintThe value to search for.

Returns: int

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

NameTypeDefaultDescription
idArray<float>The sorted array of floats to search.
valuefloatThe 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

NameTypeDefaultDescription
idArray<int>The sorted array of integers to search.
valueintThe value to search for.

Returns: int

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

NameTypeDefaultDescription
idArray<float>The sorted array of floats to search.
valuefloatThe value to search for.

Returns: int


clear

navi
Array.clear(id: series Array<T>)

Clears all elements from the given array.

Parameters

NameTypeDefaultDescription
idseries Array<T>the array to clear.

concat

navi
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

NameTypeDefaultDescription
id1Array<T>The first array to concatenate.
id2Array<T>The second array to concatenate.

Returns: Array<T>


copy

navi
Array.copy(id: Array<T>): Array<T>

Creates a copy of the given array and returns the new id.

Parameters

NameTypeDefaultDescription
idArray<T>the array to copy.

Returns: Array<T>


covariance

Calculates the covariance between two arrays of the same type T.

Parameters

NameTypeDefaultDescription
id1Array<float>The first input array.
id2Array<float>The second input array.
biasedanytrueIf true, the function uses biased estimation (dividing by n); if false, it uses unbiased estimation (dividing by n-1).

Returns: float

Calculates the covariance between two arrays.

Parameters

NameTypeDefaultDescription
id1Array<int>The first input array.
id2Array<int>The second input array.
biasedanytrueIf true, the function uses biased estimation (dividing by n); if false, it uses unbiased estimation (dividing by n-1).

Returns: float

Calculates the covariance between two arrays.

Parameters

NameTypeDefaultDescription
id1Array<int>The first input array.
id2Array<float>The second input array.
biasedanytrueIf true, the function uses biased estimation (dividing by n); if false, it uses unbiased estimation (dividing by n-1).

Returns: float

Calculates the covariance between two arrays.

Parameters

NameTypeDefaultDescription
id1Array<float>The first input array.
id2Array<int>The second input array.
biasedanytrueIf 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

NameTypeDefaultDescription
idArray<bool>the array to check.

Returns: bool

Checks if every element in the given array evaluates to true.

Parameters

NameTypeDefaultDescription
idArray<int>the array to check.

Returns: bool

Checks if every element in the given array evaluates to true.

Parameters

NameTypeDefaultDescription
idArray<float>the array to check.

Returns: bool


fill

navi
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

NameTypeDefaultDescription
idArray<T>the array to fill.
valueTThe value to fill with.
index_fromint0The starting index (inclusive).
index_tointnaThe ending index (exclusive). When na, denotes end of array.

first

navi
Array.first(id: Array<T>): T

Returns the first element of the given array.

Parameters

NameTypeDefaultDescription
idArray<T>the array to retrieve the first element from.

Returns: T


get

navi
Array.get(id: Array<T>, index: int): T

Returns the element at the specified index from the given array.

Parameters

NameTypeDefaultDescription
idArray<T>the array to retrieve the element from.
indexintThe index of the element to retrieve.

Returns: T


includes

navi
Array.includes(id: Array<T>, value: T): bool

Checks if the given array includes the specified value.

It returns true if the value is found in the array, and false otherwise.

Parameters

NameTypeDefaultDescription
idArray<T>the array to search.
valueTThe value to search for.

Returns: bool


indexof

navi
Array.indexof(id: Array<T>, value: T): int

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

NameTypeDefaultDescription
idArray<T>the array to search.
valueTThe value to search for.

Returns: int — The zero-based index of the first occurrence, or -1 if not found.


insert

navi
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

NameTypeDefaultDescription
idArray<T>the array to modify.
indexintThe index at which to insert the value.
valueTThe value to insert.

join

Joins the elements of the given array into a single string, with each element separated by the specified separator.

Parameters

NameTypeDefaultDescription
idArray<int>the array of integers to join.
separatorstringThe separator string to place between elements.

Returns: string

Joins the elements of the given array into a single string, with each element separated by the specified separator.

Parameters

NameTypeDefaultDescription
idArray<float>the array of floats to join.
separatorstringThe separator string to place between elements.

Returns: string

Joins the elements of the given array into a single string, with each element separated by the specified separator.

Parameters

NameTypeDefaultDescription
idArray<string>the array of strings to join.
separatorstringThe separator string to place between elements.

Returns: string


last

navi
Array.last(id: Array<T>): T

Returns the last element of the given array.

Parameters

NameTypeDefaultDescription
idArray<T>the array to retrieve the last element from.

Returns: T


lastindexof

navi
Array.lastindexof(id: Array<T>, value: T): int

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

NameTypeDefaultDescription
idArray<T>the array to search.
valueTThe 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

NameTypeDefaultDescription
idArray<int>the input array of integers.
nthint0Which maximum to return (0 for the largest, 1 for the second largest, etc.).

Returns: int

Returns the nth maximum value from the given id.

Parameters

NameTypeDefaultDescription
idArray<float>the input array of floats.
nthint0Which maximum to return (0 for the largest, 1 for the second largest, etc.).

Returns: float


median

Returns the median value of the elements in the given id.

Parameters

NameTypeDefaultDescription
idArray<int>the input array of integers.

Returns: float

Returns the median.

Parameters

NameTypeDefaultDescription
idArray<float>the input array of floats.

Returns: float


min

Returns the nth minimum value from the given id.

Parameters

NameTypeDefaultDescription
idArray<int>the input array of integers.
nthint0Which minimum to return (0 for the smallest, 1 for the second smallest, etc.).

Returns: int

Returns the nth minimum value from the given id.

Parameters

NameTypeDefaultDescription
idArray<float>the input array of floats.
nthint0Which minimum to return (0 for the smallest, 1 for the second smallest, etc.).

Returns: float


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

NameTypeDefaultDescription
idArray<int>the input array of integers.

Returns: int — The most frequently occurring value, or the smallest among tied values.

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

NameTypeDefaultDescription
idArray<float>the input array of floats.

Returns: float — 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

NameTypeDefaultDescription
idArray<int>the input array of integers.
indexintThe 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.

Returns the percentile rank of the element at the specified index in the given array.

Parameters

NameTypeDefaultDescription
idArray<float>the input array of floats.
indexintThe 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

NameTypeDefaultDescription
idArray<int>the input array of integers.
percentagefloatThe percentile value (0-100).

Returns: float

Returns value at percentile with linear interpolation.

Parameters

NameTypeDefaultDescription
idArray<float>the input array of floats.
percentagefloatThe 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

NameTypeDefaultDescription
idArray<int>the input array of integers.
percentagefloatThe percentile value (0-100).

Returns: float

Returns value at percentile with nearest-rank.

Parameters

NameTypeDefaultDescription
idArray<float>the input array of floats.
percentagefloatThe percentile value (0-100).

Returns: float


pop

navi
Array.pop(id: Array<T>): T

Removes and returns the last element from the given id.

Parameters

NameTypeDefaultDescription
idArray<T>the array from which to pop an element.

Returns: T


push

navi
Array.push(id: Array<T>, value: T)

Appends the given value to the end of the array.

Parameters

NameTypeDefaultDescription
idArray<T>the array to which the value will be appended.
valueTThe 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

NameTypeDefaultDescription
idArray<int>the input array of integers.

Returns: int

Returns the range (difference between the maximum and minimum values) of the elements in the given array.

Parameters

NameTypeDefaultDescription
idArray<float>the input array of floats.

Returns: float


remove

navi
Array.remove(id: Array<T>, index: int): T

Removes the element at the specified index from the given array and returns the removed element.

Parameters

NameTypeDefaultDescription
idArray<T>the array to modify.
indexintThe index of the element to remove.

Returns: T


reverse

navi
Array.reverse(id: Array<T>)

Reverses the order of elements in the given array.

Parameters

NameTypeDefaultDescription
idArray<T>the array to reverse.

set

navi
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

NameTypeDefaultDescription
idArray<T>the array to modify.
indexintThe index of the element (supports negative indexing).
valueTThe value to set at the specified index.

shift

navi
Array.shift(id: Array<T>): T

Removes and returns the first element from the given id.

Parameters

NameTypeDefaultDescription
idArray<T>the array from which to shift an element.

Returns: T


size

navi
Array.size(id: Array<T>): int

Returns the size (number of elements) of the given id.

Parameters

NameTypeDefaultDescription
idArray<T>the array whose size is to be determined.

Returns: int


slice

navi
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

NameTypeDefaultDescription
idArray<T>the array to slice.
index_fromint0The starting index (inclusive).
index_tointnaThe 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

NameTypeDefaultDescription
idArray<bool>the array to check.

Returns: bool

Checks if at least one element in the given array evaluates to true.

Parameters

NameTypeDefaultDescription
idArray<int>the array to check.

Returns: bool

Checks if at least one element in the given array evaluates to true.

Parameters

NameTypeDefaultDescription
idArray<float>the array to check.

Returns: bool


sort

Sorts the elements of the given array in ascending or descending order.

Parameters

NameTypeDefaultDescription
idArray<int>the array of integers to sort.
orderanySortOrder.AscendingThe sort order.

Sorts array elements.

Parameters

NameTypeDefaultDescription
idArray<float>the array of floats to sort.
orderanySortOrder.AscendingThe sort order.

Sorts array elements.

Parameters

NameTypeDefaultDescription
idArray<string>the array of strings to sort.
orderanySortOrder.AscendingThe sort order.

sort_indices

Returns an array of indices that would sort the given id.

Parameters

NameTypeDefaultDescription
idArray<int>the array of integers to analyze.
orderanySortOrder.AscendingThe sort order.

Returns: Array<int> — an array of original indices rearranged so that result.get(i).get() yields the i-th sorted element.

Returns sort indices.

Parameters

NameTypeDefaultDescription
idArray<float>the array of floats to analyze.
orderanySortOrder.AscendingThe sort order.

Returns: Array<int>

Returns sort indices.

Parameters

NameTypeDefaultDescription
idArray<string>the array of strings to analyze.
orderanySortOrder.AscendingThe sort order.

Returns: Array<int>


standardize

Standardizes the elements of the given array by subtracting the mean and dividing by the standard deviation.

Parameters

NameTypeDefaultDescription
idArray<float>the input array of floats.

Returns: Array<float> — a new array where each element is (value - mean) / stdev (z-scores).

Standardizes the elements of the given array by subtracting the mean and dividing by the standard deviation.

Parameters

NameTypeDefaultDescription
idArray<int>the input array of integers.

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

NameTypeDefaultDescription
idArray<float>the input array of floats.
biasedanytrueIf true, the function uses biased estimation (dividing by n); if false, it uses unbiased estimation (dividing by n-1).

Returns: float

Calculates the standard deviation of the elements in the given array.

Parameters

NameTypeDefaultDescription
idArray<int>the input array of integers.
biasedanytrueIf 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

NameTypeDefaultDescription
idArray<int>the input array of integers.

Returns: int

Calculates the sum of the elements in the given array.

Parameters

NameTypeDefaultDescription
idArray<float>the input array of floats.

Returns: float


unshift

navi
Array.unshift(id: Array<T>, value: T)

Adds the specified value to the beginning of the given array.

Parameters

NameTypeDefaultDescription
idArray<T>the array to modify.
valueTThe value to add to the beginning.

variance

Calculates the variance of the elements in the given id.

Parameters

NameTypeDefaultDescription
idArray<int>the input array of integers.
biasedanytrueIf true, the function uses biased estimation (dividing by n); if false, it uses unbiased estimation (dividing by n-1).

Returns: float

Calculates the variance of the elements in the given id.

Parameters

NameTypeDefaultDescription
idArray<float>the input array of floats.
biasedanytrueIf true, the function uses biased estimation (dividing by n); if false, it uses unbiased estimation (dividing by n-1).

Returns: float

Released under the MIT License.