stack 🔗

A “stack” is a data structure where you can ‘push’ a value onto the top of the stack, or you can ‘pop’ a value off the top of the stack. The popped value is returned, but is no longer on the stack. This implementation of the stack also lets you find the ith element in the stack, starting from the top, and lets you see the size of the stack. See: Wikipedia: Stack

stack.push = function(value:any)-->void

When called, adds value to the top of the stack.
stack.push(5) adds 5 to the top of the stack.

stack.pop = function()-->any

When called, removes the top item of the stack, and returns it.

If the stack is formed by
stack.push(1)
stack.push(2)
stack.push(3)
then
stack.pop()–>3
stack.pop()–>2
stack.pop()–>1
stack.pop()–>nil

stack.size = integer

Returns the current size of the stack.

stack[i] = any

stack[i] returns the ith value in the stack, counting from the top, or nil if there aren’t i values in the stack. The stack remains unchanged.

If the stack is formed by stack.push(1)
stack.push(2)
stack.push(3)
then
stack[1]–>3
stack[2]–>2
stack[3]–>1
stack[4]–>nil

[integer] 🔗

stack.[integer] --> any


stack[i] returns the ith value in the stack, counting from the top, or nil if there aren’t i values in the stack. The stack remains unchanged.

If the stack is formed by stack.push(1)
stack.push(2)
stack.push(3)
then
stack[1]–>3
stack[2]–>2
stack[3]–>1
stack[4]–>nil

pop 🔗

stack.pop --> fun():any

When called, removes the top item of the stack, and returns it.

If the stack is formed by stack.push(1)
stack.push(2)
stack.push(3)
then
stack.pop()–>3
stack.pop()–>2
stack.pop()–>1
stack.pop()–>nil

push 🔗

stack.push --> fun(value: any)

When called, adds value to the top of the stack.
stack.push(5) adds 5 to the top of the stack.

size 🔗

stack.size --> integer

Returns the current size of the stack.