Site under construction! :3
Array (arr
) ξ―
Propertiesξ―
length
ξ―
Returns the length of the array as an int
.
Methodsξ―
all(func: function = (el => el)) -> bool
ξ―
Returns true
only if all elements of the array return true
when passed as an argument into func
, else it returns false
.
arr = [0, 1, 2, 3, 4] arr.all((el => el > 3)) # false
any(func: function = (el => el)) -> bool
ξ―
Returns true
if any element of the array returns true
when passed as a arguments into func
, else it returns false
.
arr = [0, 1, 2, 3, 4] arr.any((el => el > 3)) # true
combine(*arrays: array, allow_duplicates: bool = true) -> array
ξ―
Combines the elements of arrays
into the instance array.
arr1 = [1, 2, 3] arr2 = [3, 4, 5] x = array.combine(arr1, arr2) # [1, 2, 3, 3, 4, 5]
contains(element: any) -> bool
ξ―
Returns true
if the array contains at least one element that is equal to element
, else it returns false
.
arr = ["a", "b", "c", "a", "b", "a"] arr.contains("d") # false
count(condition: any) -> int
ξ―
Returns the number of elements in the array that match condition
.
arr = ["a", "b", "c", "a", "b", "a"] arr.count("a") # 3
extend(*arrays: array, allow_duplicates: bool = true) -> none
ξ―
Combines the elements of arrays
into the instance array.
arr1 = [1, 2, 3] arr2 = [3, 4, 5] arr1.extend(arr2) # arr1 = [1, 2, 3, 3, 4, 5]
filter(func: function = (el => el)) -> none
ξ―
Removes all elements of the instance array which do not return true
when passed as arguments into func
arr = ["a", true, 0, "b", 2, ["c", "d"]] arr.filter((el => type(el) is string)) # arr = ["a", "b"]
find(func: function = (el => el)) -> any
ξ―
Returns the first element of the instance array returns true
when passed as an argument into func
.
arr = ["a", true, 0, "b", 2, ["c", "d"]] x = arr.find((el => type(el) is string)) # "a"
find_all(func: function = (el => el)) -> generator[any]
ξ―
Returns a generator
of all the elements of the instance array which return true
when passed as a arguments into func
.
arr = ["a", true, 0, "b", 2, ["c", "d"]] items = arr.find_all((el => type(el) is string)) next(items) # a next(items) # b next(items) # undefined
flatten() -> none
ξ―
Modifies the instance array so that all nested array items are de-nested and lie "flat" with all other elements. Empty arrays are ignored.
arr = ["a", ["b", none], ["c", [[], "d"]]] arr.flatten() # ["a", "b", none, "c", "d"]
index(condition: any) -> int
ξ―
Returns the index of the first element in the instance array that satisfy condition
.
arr = ["a", true, 0, "b", 2, ["c", "d"]] x = arr.index((el => type(el) is string)) # 0
index_all(condition: any) -> generator[int]
ξ―
Returns a generator
of the indices of all elements in the instance array that satisfy condition
.
arr = ["a", true, 0, "b", 2, ["c", "d"]] indices = arr.index_all((el => type(el) is string)) next(indices) # 0 next(indices) # 3 next(indices) # undefined
insert(element: any, index: index) -> none
ξ―
Inserts element
at position index
.
arr = [0, 1, 2, 3, 4] arr.insert("a", 2) # arr = [0, 1, "a", 2, 3, 4]
join(separator: str = "") -> str
ξ―
Returns the contents of the array concatenated as a string, separated by the string separator
.
arr = ["a", "b", "c", "d"] x = arr.join("-") # "a-b-c-d"
map(func: function) -> none
ξ―
Maps each item of the instance array to the returned array by passing them as arguments into func
.
arr = [0, 1, 2, 3, 4] arr.map((el => el * 2)) # arr = [0, 2, 4, 6, 8]
pop(index: index = -1) -> any
ξ―
Removes (pops) and returns the element at position index
of the instance array.
arr = [0, 1, 2, 3, 4] x = arr.pop() # 4 print(arr) # [0, 1, 2, 3]
push(element: any) -> none
ξ―
Appends (pushes) element
to the end of the instance array.
arr = [0, 1, 2, 3, 4] arr.push(5) print(arr) # [0, 1, 2, 3, 4, 5]
remove(element: any) -> none
ξ―
Removes the first element of the instance array that is equal to element
.
arr = ["a", "b", "c", "a", "a"] arr.remove("a") print(arr) # ["b", "c", "a", "a"]
remove_all(element: any) -> none
ξ―
Removes all elements of the instance array that are equal to element
.
arr = ["a", "b", "c", "a", "a"] arr.remove_all("a") print(arr) # ["b", "c"]
reverse() -> none
ξ―
Reverses the order of elements in the instance array.
arr = [0, 1, 2, 3, 4] arr.reverse() # arr = [4, 3, 2, 1, 0]
replace(condition: any, content: any) -> none
ξ―
TODO
sort(key: any = none, descending: bool = false) -> none
ξ―
Sorts the array in the order specified by key
.
By default, this sorts numbers by value, and strings alphabetically.
arr = [3, 1, 4, 2, 0] arr.sort() # arr = [0, 1, 2, 3, 4]