Home Reference Source Test Repository
public class | source

Stack

Stack containers for simple FILO data structures.

Constructor Summary

Public Constructor
public

Constructs a Stack instance.

Member Summary

Public Members
public get

size: number: *

Getter for size, allows access as a property

public

stack: *

Method Summary

Public Methods
public

clear()

Clear the stack.

public

forEach(callback: function(item: *): boolean)

Helper function to loop through all items in the stack.

public

has(item: *): boolean

Check if the stack contains the specified item.

public

peek(): *

Get the item at the top of the stack.

public

pop(): *

Get and remove the item at the top of the stack.

public

push(item: *)

Add item to the top of the stack.

Public Constructors

public constructor source

Constructs a Stack instance.

Public Members

public get size: number: * source

Getter for size, allows access as a property

Return:

number

Size of the stack.

public stack: * source

Public Methods

public clear() source

Clear the stack.

public forEach(callback: function(item: *): boolean) source

Helper function to loop through all items in the stack.

Params:

NameTypeAttributeDescription
callback function(item: *): boolean

Callback function called for each item in the stack. If the return value is false, the remaining items are skipped.

public has(item: *): boolean source

Check if the stack contains the specified item.

Params:

NameTypeAttributeDescription
item *

Item to check.

Return:

boolean

Whether or not the item is in the stack.

Throw:

Error

Throws an error if checking null or undefined.

public peek(): * source

Get the item at the top of the stack.

Return:

* (nullable: true)

Item at the top of the stack, or null if the stack is empty.

public pop(): * source

Get and remove the item at the top of the stack.

Return:

* (nullable: true)

Item at the top of the stack, or null if the stack is empty.

public push(item: *) source

Add item to the top of the stack.

Params:

NameTypeAttributeDescription
item *

The item to add.

Throw:

Error

Throws error if attempting to add null or undefined.