-
Notifications
You must be signed in to change notification settings - Fork 0
Array
Array.__invoke(data...)
Returns an array containing the given data as elements.
Array.create(size = 0, init = null)
Returns a newly-created array. You can optionally specify a size and an initial value to fill the array.
Array.clone(array)
Returns a copy of the given array.
Array.sizeOf(array)
Returns the size of the given array.
Array.push(array, data...)
Add some data to the end of the array.
Array.unshift(array, data...)
Add some data to the start of the array.
Array.pop(array)
Removes the last element of the array and returns it.
Array.shift(array)
Removes the first element of the array and returns it.
Array.slice(array, start = 0, end = Array.sizeOf(array)))
Returns a slice of the given array. You can optionally specify start index and end index.
Array.insert(array, index, data...)
Inserts some data at the given index in the array.
Array.remove(array, index, count = 1)
Removes some elements at the given index in the array.
Array.clear(array)
Empties the given array.
Array.flat(arrays, depth = 1)
Flatten the given array of arrays. You can optionally specify the flattening depth.
Array.reverse(array)
Reverse the given array in place and returns array
itself.
Array.unpack(array, names, loose = false)
Unpacks the elements in the given array and
stores them in variables specified by names
.
When option loose
is false(default),
errors will be raised if there are more names than available values;
otherwise, excess names result in null
values.
Array.indexOf(array, value)
Returns the index where the given value occurs in the given array
for the first time. Returns -1
if the value never occurs.
Array.lastIndexOf(array, value)
Returns the index where the given value occurs in the given array
for the last time. Returns -1
if the value never occurs.
Array.includes(array, value)
Returns a boolean telling whether the given array includes specific value.
Array.sort(array, compareFn?)
Sorts the given array according to the given comparing function.
Two elements are swapped when the comparing function returns a positive value.
The default comparing function sorts elements in ascending order.
(Using Array.prototype.sort
in JavaScript source code.)
Array.forEach(array, callback)
Iterates array
and invokes callback
on each element.
The callback is provided with 3 arguments: element
, index
and array
.
Array.map(array, callback)
Maps array
to a new one, where new elements are returned by callback
.
(The original array won't be modified.)
The callback is provided with 3 arguments: element
, index
and array
.
For example,
a = [1, 2, 3];
b = a:map((x) => (2 ** x));
"b becomes [2, 4, 8] here.";
Array.filter(array, callback)
Filters array
and returns a new array representing the result.
(Elements are kept only when callback
returns true
;
The original array won't be modified.)
The callback is provided with 3 arguments: element
, index
and array
.
For example,
a = [1, 2, 3];
b = a:filter((x) => ((x & 1) === 1)); "odd";
"b becomes [1, 3] here.";
Array.every(array, callback)
Returns false
if callback
returns false
for any element in array
;
returns true
if callback
returns true
for all elements or array
is empty.
The callback is provided with 3 arguments: element
, index
and array
.
For example,
a = [1, 2, 3];
allPositive = a:every((x) => (x > 0)); "true";
allOdd = a:every((x) => ((x & 1) === 1)); "false";
Array.some(array, callback)
Returns true
if callback
returns true
for any element in array
;
returns false
if callback
returns false
for all elements or array
is empty.
The callback is provided with 3 arguments: element
, index
and array
.
For example,
a = [1, 2, 3];
someOdd = a:some((x) => ((x & 1) === 1)); "true";
someNegative = a:some((x) => (x < 0)); "false";
Array.findIndex(array, callback)
Returns the first index where callback
returns true
;
throws an error if callback
returns false
for all elements.
The callback is provided with 3 arguments: element
, index
and array
.
For example,
a = [1, 2, 3];
indexOdd = a:findIndex((x) => ((x & 1) === 1)); "0";
indexNeg = a:findIndex((x) => (x < 0)); "Error!";
Array.find(array, callback)
Similar to Array.findIndex
,
but returns the element instead of the index.
For example,
a = [1, 2, 3];
indexOdd = a:findIndex((x) => ((x & 1) === 1)); "1";
indexNeg = a:findIndex((x) => (x < 0)); "Error!";