Array Functions

[!Note] remove, removeElement, slice, removeNulls and sort return an array of the type of the given array: int[] gives int[], and Integer[] gives Integer[]. add, addAll and addElement change the type only to fit an added element: an int keeps an int[], an Integer or a null element makes it Integer[], and a double makes it double[]. flatten returns an array of the common type of the elements: int[][] gives int[], and an int[] with an Integer[] gives Integer[]. A boxed array stays boxed, so its null elements are kept. Separate values passed instead of an array, as in sort(3, 1, 2), count as an array of their common type.

Function Description
add(array,element) Returns a new array that includes the original array plus the newly added element at the end.
Parameters:
    array: The array to which the element is to be added.
    element: One or more elements to be added, or an array of elements. This is a varargs parameter, allowing for multiple elements to be listed.
Examples:
    add(states, “Texas”) - Creates a new array with all elements of states plus “Texas” at the end.
    add(states, “California”, “Nevada”, “Oregon”) - Creates a new array with all elements of states plus “California”, “Nevada”, and “Oregon” added at the end.
    add(states, newStates) - Creates a new array with all elements of states plus all elements of newStates added at the end.
add(array1, array2, …, arrayN) Adds all elements of the provided arrays into a new array.
addAll(array1, array2) Adds all elements of the given arrays into a new array.
addElement(array, index, element) Returns a new array that includes a specific element inserted at a given index within the original array.
Parameters:
    array: The array into which the elements to be inserted.
    index: The position in the array where the new elements must be inserted. This index starts at zero.
    element: One or more elements to be inserted, or an array of elements. This is a varargs parameter, allowing for multiple elements to be listed.
Examples:
    addElement(states, 3, “Texas”) - Creates a new array with all elements of states plus “Texas” at the 4th position in the states array.
    addElement(states, 2, “California”, “Nevada”, “Oregon”) - Creates a new array with all elements of states plus “California”, “Nevada”, and “Oregon” starting at the 3rd position in the states array.
    addElement(states, 1, newStates) - Creates a new array with all elements of states plus all elements of newStates array starting at the 2nd position in the states array.
allFalse(Boolean[]) Returns true if all array elements are false.
allNo(Boolean[]) Synonym of allFalse. Returns true if all array elements are false.
anyFalse(Boolean[]) Returns true if any array element is false.
anyNo(Boolean[]) Synonym of anyFalse. Returns true if any array element is false.
allTrue(Boolean[]) Returns true if all array elements are true.
allYes(Boolean[]) Synonym of allTrue. Returns true if all array elements are true.
anyTrue(Boolean[]) Returns true if any array element is true.
anyYes(Boolean[]) Synonym of anyTrue. Returns true if any array element is true.
avg(array) Returns the arithmetic average of the array of number elements.
big(array, int position) Removes null values from array, sorts an array in descending order and returns the value at position ‘position’. A NaN value makes the result NaN.
concatenate(array) Joins several values in one text string.
contains(array, elem) Checks if the value is in the given array.
Instead of an array, this function can accept a list, a set, a range or an array of ranges. When the value is an array, checks that all its values are there.
indexOf(array[], elem) Finds the index of the given value in the array.
intersection(String[] array1, String[] array2) Returns a new array containing elements common to the two arrays.
isEmpty(array) Checks if an array is empty or null.
flatten(arrayN) Returns a flatten array with values from arrayN. Returns a single dimension array of elements. Converts a matrix into a list.
Returns null if every given array is null.
length(array) Returns the number of elements in the array. It is more preferable than the array.length syntax.
max(array) Returns the maximal value in the array of numbers. Empty values are skipped, and a NaN value makes the result NaN.
median(array) Returns the middle number in a group of supplied numbers. For example, =MEDIAN(1,2,3,4,5) returns 3.
The result is a floating value. Empty values are skipped, and a NaN value makes the result NaN.
min(array) Returns the minimal value in the array of numbers. Empty values are skipped, and a NaN value makes the result NaN.
noNulls(array) Checks if the array is non-empty and has only non-empty elements.
product(array values) Multiplies the numbers from the provided array and returns the product as a number.
remove(array, int index) Removes the element at the specified position from the specified array.
Returns null if the array is null. Fails if the position is outside the array.
removeElement(array, element) Removes the first occurrence of the specified element from the specified array.
removeNulls(T[] array) Returns a new array without null elements.
slice(array, int startIndexInclusive,
int endIndexExclusive)
Returns a part of the array from startIndexInclusive to endIndexExclusive.
small(array, int position) Removes null values from array, sorts an array in ascending order and returns the value at position ‘position’. A NaN value makes the result NaN.
sort(array) Sorts the specified array of values into ascending order, according to the natural ordering of its elements.
sum(array) Returns the sum of numbers in the array.