Arrays reference
The 44 functions and 0 values of array: signature, effects, phase, cost and tested examples.
An array is an ordered list of values of one kind. Many functions here are written as methods: a.push(x) is array.push(a, x).
Functions#
array.abs#
array.abs([array])
A new array with the absolute value of each element.
- Effects: builds a new value whose size follows its arguments (counted in the memory ledger).
- Phase: every bar.
- Cost: allocates: the memory ledger counts what it builds.
- Returns: an array.
array.all#
array.all([array])
True when the array is not empty and every element is true.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
- Returns: true or false.
array.any#
array.any([array])
True when at least one element is true.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
- Returns: true or false.
array.at#
array.at(array, index)
The element at an index.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
- Examples: Guarded read, Read past the end of an array.
array.avg#
array.avg([array])
A statistic of the elements.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
array.binary_search#
array.binary_search([array], [value])
The index of a value in a sorted array, or -1 when the value is not there.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
- Returns: a whole number.
array.binary_search_leftmost#
array.binary_search_leftmost([array], [value])
The index of the first element equal to the value in a sorted array; when none is equal, the index of the element just below where the value would sit.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
- Returns: a whole number.
array.binary_search_rightmost#
array.binary_search_rightmost([array], [value])
The index of the last element equal to the value in a sorted array; when none is equal, the index of the element just above where the value would sit.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
- Returns: a whole number.
array.clear#
array.clear(array)
Removes every element.
- Effects: changes a collection in place.
- Phase: every bar.
- Cost: a fixed number of operations.
array.concat#
array.concat([array], [other])
Appends the elements of another array to the array and returns it.
- Effects: changes a collection in place; builds a new value whose size follows its arguments (counted in the memory ledger).
- Phase: every bar.
- Cost: allocates: the memory ledger counts what it builds.
- Returns: the array.
array.contains#
array.contains([array], [value])
True when the array holds the value.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
array.copy#
array.copy([array])
A copy of the array.
- Effects: builds a new value whose size follows its arguments (counted in the memory ledger).
- Phase: every bar.
- Cost: allocates: the memory ledger counts what it builds.
array.covariance#
array.covariance([array], [other], [biased])
The covariance of two arrays of the same size; pairs that hold na are skipped, and biased divides by the count instead of the count minus one.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
- Returns: a number.
array.fill#
array.fill([array], [value], [from], [to])
Sets the elements from index from up to, not including, to to one value; without a range it fills the whole array.
- Effects: changes a collection in place.
- Phase: every bar.
- Cost: a fixed number of operations.
array.first#
array.first([array])
The first or last element.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
array.index_of#
array.index_of([array], [value])
The index of the first or last element equal to the value, or -1.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
array.insert#
array.insert([array], [index], [value])
Inserts a value at an index.
- Effects: changes a collection in place; builds a new value whose size follows its arguments (counted in the memory ledger).
- Phase: every bar.
- Cost: allocates: the memory ledger counts what it builds.
array.join#
array.join([array], [separator])
The elements as one text, with separator between.
- Effects: builds a new value whose size follows its arguments (counted in the memory ledger).
- Phase: every bar.
- Cost: allocates: the memory ledger counts what it builds.
array.last#
array.last([array])
The first or last element.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
- Examples: Guarded read, Read past the end of an array.
array.last_index_of#
array.last_index_of([array], [value])
The index of the first or last element equal to the value, or -1.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
array.max#
array.max([array], [nth])
A statistic of the elements.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
- Examples: Rolling median band, Array read with brackets.
array.median#
array.median([array])
A statistic of the elements.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
- Examples: Rolling median band.
array.min#
array.min([array], [nth])
A statistic of the elements.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
- Examples: Rolling median band, Array read with brackets.
array.mode#
array.mode([array])
A statistic of the elements.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
array.new#
array.new([size], [initial])
Makes an array of size elements, each initial.
- Effects: builds a new value whose size follows its arguments (counted in the memory ledger).
- Phase: every bar.
- Cost: allocates: the memory ledger counts what it builds.
array.percent_rank#
array.percent_rank([array], [index])
The percentage of the elements that are less than or equal to the element at index.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
- Returns: a number from 0 to 100.
array.percentile#
array.percentile([array], [percent])
The value at a percentage of the sorted elements, interpolated between the two closest ranks.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
- Returns: a number.
- Examples: Rolling median band, Array read with brackets.
array.percentile_nearest#
array.percentile_nearest([array], [percent])
The value at a percentage of the sorted elements, taken at the nearest rank.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
- Returns: a number.
array.pop#
array.pop(array)
Removes and gives the last element.
- Effects: changes a collection in place.
- Phase: every bar.
- Cost: a fixed number of operations.
array.push#
array.push(array, value)
Adds a value at the end.
- Effects: changes a collection in place; builds a new value whose size follows its arguments (counted in the memory ledger).
- Phase: every bar.
- Cost: allocates: the memory ledger counts what it builds.
- Examples: Rolling median band, Swing high path, Guarded read, Array read with brackets.
array.range#
array.range([array])
A statistic of the elements.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
array.remove#
array.remove(array, index)
Removes and gives the element at an index.
- Effects: changes a collection in place.
- Phase: every bar.
- Cost: a fixed number of operations.
array.reverse#
array.reverse([array])
Reverses the order in place.
- Effects: changes a collection in place.
- Phase: every bar.
- Cost: a fixed number of operations.
array.set#
array.set(array, index, value)
Sets the element at an index.
- Effects: changes a collection in place.
- Phase: every bar.
- Cost: a fixed number of operations.
array.shift#
array.shift([array])
Removes and gives the first element.
- Effects: changes a collection in place.
- Phase: every bar.
- Cost: a fixed number of operations.
- Examples: Rolling median band, Swing high path, Array read with brackets.
array.size#
array.size(array)
The number of elements.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
- Examples: Rolling median band, Swing high path, Guarded read, Array read with brackets.
array.slice#
array.slice([array], [from], [to])
A copy of part of the array.
- Effects: builds a new value whose size follows its arguments (counted in the memory ledger).
- Phase: every bar.
- Cost: allocates: the memory ledger counts what it builds.
array.sort#
array.sort([array], [order])
Sorts the array in place, ascending or descending.
- Effects: changes a collection in place.
- Phase: every bar.
- Cost: a fixed number of operations.
array.sort_indices#
array.sort_indices([array], [order])
A new array with the indexes that would put the elements in order, ascending or descending.
- Effects: builds a new value whose size follows its arguments (counted in the memory ledger).
- Phase: every bar.
- Cost: allocates: the memory ledger counts what it builds.
- Returns: an array of whole numbers.
array.standardize#
array.standardize([array])
A new array with each element as a z-score: its distance from the mean in standard deviations.
- Effects: builds a new value whose size follows its arguments (counted in the memory ledger).
- Phase: every bar.
- Cost: allocates: the memory ledger counts what it builds.
- Returns: an array of numbers.
array.stdev#
array.stdev([array], [biased])
A statistic of the elements.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
array.sum#
array.sum([array])
A statistic of the elements.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.
array.unshift#
array.unshift([array], [value])
Adds a value at the start.
- Effects: changes a collection in place; builds a new value whose size follows its arguments (counted in the memory ledger).
- Phase: every bar.
- Cost: allocates: the memory ledger counts what it builds.
array.variance#
array.variance([array], [biased])
A statistic of the elements.
- Effects: none: the result depends on the arguments only.
- Phase: every bar.
- Cost: a fixed number of operations.