Array
-
construct(length,value)
Returns an array of length
length
filled withvalue
. ThrowsError
if length is negative andTypeError
iflength
is not anInt
Example:
new Array(3,0) //[0,0,0]
-
push(value)
Appends
value
to its endExample
let arr = [1,2] arr.push(3) arr[1,2,3]
-
pop()
Removes the last element and returns it. Throws
IndexError
if it is emptyExample
let arr = [1,2] arr.pop() //2
-
len()
Returns the length of the array
Example
let arr = [1,2] arr.len() //2
-
insert(position,value)
Inserts
value
atposition
. Throws IndexError ifposition
is greater than its length andTypeError
ifposition
is not anInt
Example
let arr = [1,2] arr.insert(0,3) arr //[3,1,2]
-
remove(position)
Removes the value at
position
. Throws IndexError ifposition
is greater than or equal to its length andTypeError
ifposition
is not anInt
Example
let arr = [1,2] arr.remove(0) arr //[2]
-
clear()
Removes all elements of the array
Example
let arr = [1,2] arr.clear() arr //[]
-
iter()
Returns an iterator to the elements of the array
Example:
[1,2,3].iter().collect() //[1,2,3]
-
sort(compare)
Sorts the array comparing by function
compare
.Example
let arr = [4,1,3,2] arr.sort(|x,y|x<y) arr //[1,2,3,4]