Return to homepage

DOSATO

Copyright © 2024 Sebastiaan Heins

3.3 Arrays

Functions

array sort (array arr, function compare_function = ?)

Optionally, a compare function can be passed to sort the array in a custom way.
Sorting is based of the numerical value of the elements. (or the return value of the compare function)

array push (array arr, var value)

Adds the given value to the end of the given array, and returns the array.

var pop (array arr)

Removes the last element from the given array, and returns the popped value.

var shift (array arr)

Removes the first element from the given array, and returns the shifted value.

array unshift (array arr, var value)

Adds the given value to the start of the given array, and returns the array.

array slice (array arr, long start, long end = ?)

Returns a slice of the given array, starting at the given start index, and ending at the given end index.
If no end index is given, the slice will go to the end of the array.

array splice (array arr, long start, long delete_count = ?)

Removes a number of elements from the given array, starting at the given start index, then returns a soft copy.
If no delete count is given, all elements from the start index to the end of the array will be removed.

long indexof (array arr, var value)

Returns the index of the first occurence of the given value in the given array.
If the value is not found, -1 is returned.

long lastindexof (array arr, var value)

Returns the index of the last occurence of the given value in the given array.
If the value is not found, -1 is returned.

array reverse (array arr)

Returns a copy of the given array, with the elements in reverse order.

array fill (var element, int amount)

Returns an array of the given amount, filled with copies of the given element.

array range (long end)
array range (long start, long end, long step = 1)

Returns an array of integers, starting at the given start index, ending at the given end index, and incrementing by the given step.
If no step is given, the default value of 1 is used.
If only 1 parameter is given, the default start value of 0 is used. and the given parameter is used as the end value.

array rangef (double end)
array rangef (double start, double end, double step = 1.0)

Returns an array of doubles, starting at the given start index, ending at the given end index, and incrementing by the given step.
If no step is given, the default value of 1.0 is used.
If only 1 parameter is given, the default start value of 0.0 is used. and the given parameter is used as the end value.

long counter ()

Returns the current value of the counter.
The counter is a global variable that is incremented by 1 every time it is called.

long setcounter (long value)

Sets the value of the internal counter to the given value, then returns the new value.