Constructor
new List()
Start with an empty array and store the length of the "list".
Note that we to store the length separately because the "memory" doesn't have a length that can be read.
Methods
get(position) → {null|*}
Getter to retrieve list elements.
Parameters:
| Name | Type | Description |
|---|---|---|
position |
Number | Position of element in List |
Returns:
- Type
- null | *
pop() → {*}
Pop items off of the end of our list.
Similar to push all we need to do is remove the value at the address at
the end of our list. Then just decrement length.
Returns:
- Type
- *
push(value)
Add and item to the end of the list.
Adding a value after the end of our list. Just add the value and increment the length.
Parameters:
| Name | Type | Description |
|---|---|---|
value |
* | Value that should be added to the list |
shift() → {*}
Shift function to move in the opposite direction.
Delete the first value and slide through every single item in the ist to move it down one address.
[x, a, b, c, d, e]
1 2 3 4 5
0 1 2 3 4
[a, b, c, d, e]
Returns:
- Type
- *
unshift(value)
In order to add a new item at the beginning of the list, we need to make
room for the value at the start by sliding all of the values over by one.
[a, b, c, d, e]
0 1 2 3 4
1 2 3 4 5
[x, a, b, c, d, e]
In order to slide all of the items over we need to iterate over each one
moving the prev value over.
Parameters:
| Name | Type | Description |
|---|---|---|
value |
* |