Class: Queue

Queue

new Queue()

A queue that can enqueue items at the end, and dequeue items from the front.
Source:

Members

(readonly) length :Number

The length of the queue.
Type:
  • Number
Source:

Methods

clear()

Remove all items from the queue.
Source:

contains(item)

Check whether this queue contains the specified item.
Parameters:
Name Type Description
item Object The item to search for.
Source:

dequeue() → {Object}

Dequeues an item. Returns undefined if the queue is empty.
Source:
Returns:
The the dequeued item.
Type
Object

enqueue(item)

Enqueues the specified item.
Parameters:
Name Type Description
item Object The item to enqueue.
Source:

peek() → {Object}

Returns the item at the front of the queue. Returns undefined if the queue is empty.
Source:
Returns:
The item at the front of the queue.
Type
Object

sort(compareFunction)

Sort the items in the queue in-place.
Parameters:
Name Type Description
compareFunction Queue~Comparator A function that defines the sort order.
Source:

Type Definitions

Comparator(a, b) → {Number}

A function used to compare two items while sorting a queue.
Parameters:
Name Type Description
a Object An item in the array.
b Object An item in the array.
Source:
Returns:
Returns a negative value if a is less than b, a positive value if a is greater than b, or 0 if a is equal to b.
Type
Number
Example
function compareNumbers(a, b) {
    return a - b;
}