Members
add
numberAppends new elements to the end of the sequence, and returns the new length of the sequence.
@complexity
O(n)@paramnode
T[]@returns
number const stack = new Stack([1, 2, 3, 4, 5]);console.log(stack.remove()) //[1, 2, 3, 4]
Removes and returns the last element in the stack.
@complexity
O(n)@returns
Tat
TReturns the item located at the specified index.
@complexity
𝛩(1)@paramindex
numberThe zero-based index of the desired code unit. A negative index will count back from the last item.
@returns
Tlength
numberGets or sets the length of the sequence. This is a number one higher than the highest index in the sequence.
setAt
T[] console.log(stack.setAt(1,6)) //1,6,3,4,5
Overwrites the value at the provided index with the given value. If the index is negative, then it replaces from the end of the sequence.
@complexity
𝛩(1)@paramindex
numberThe index of the value to overwrite. If the index is negative, then it replaces from the end of the sequence.
@paramvalue
TThe value to write into the provided index v.
@returns
The updated sequence.