List functions

# Name Description Complexity
1 getElement(List[T], Int): T Gets element from the list by index 2
2 cons(T, List[T]): List[T] Inserts element to the beginning of the list 2
3 size(List[T]): Int Returns the size of the list 2

getElement(List[T], Int): T

Gets element from the list by index.

getElement(arr: List[T], pos: Int): T

Parameters

arr: List[T]

List.

pos: Int

Index of the element.

Examples

getElement(["Ride", "on", "Waves"], 0)  # Returns "Ride"
getElement([false, true], 1) # Returns true

cons(T, List[T]): List[T]

Inserts element to the beginning of the list.

cons(head:T, tail: List[T]): List[T]

Parameters

head: T

Element.

tail: List[T]

List.

Examples

cons("Ride", ["on", "Waves"]) # Returns ["Ride", "on", "Waves"]
cons(1, [2, 3, 4, 5]) # Returns [1, 2, 3, 4, 5]

size(List[T]): Int

Returns the size of the list.

size(arr: List[T]): Int

Parameters

arr: List[T]

List.

Examples

size(["Ride", "on", "Waves"]) # Returns 3

results matching ""

    No results matching ""