/** Class representing each node in queue */
class Node {
  /**
   * Quickly create nodes for queue
   *
   * @constructor
   * @param {*} value - value held by node
   */
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

/** Class representing a queue */
class Queue {
  /**
   * Use Linked List structure to trade space from extra pointers
   * for constant time complexity on all operations.
   * @constructor
   */
  constructor(capacity = Infinity) {
    this.front = null;
    this.rear = null;
    this.size = 0;
    this.capacity = capacity;
  }

  /** 
   * Description: Check if queue is empty
   * Strategy: Use size property
   *
   * Time complexity: O(1)
   * Space complexity: O(1)
   *
   * @return {Boolean} - true if empty, or false otherwise
   */
  isEmpty() {
    return this.size === 0;
  }

  /** 
   * Description: Check if queue has reached capacity
   * Strategy: Check if size equals capacity
   *
   * Time complexity: O(1)
   * Space complexity: O(1)
   *
   * @return {Boolean} - true if full, or false otherwise
   */
  isFull() {
    return this.size === this.capacity;
  }

  /**
   * Description: View value at front of queue
   * Strategy: Look at front property
   *
   * Time complexity: O(1)
   * Space complexity: O(1)
   *
   * @return {*} - value at front of queue
   */
  peek() {
    if (this.front !== null) { return this.front.value; };
  }

  /**
   * Description: Add node with given input value to end of queue
   * Strategy: Use native Array push method if under capacity
   *
   * Time complexity: O(1)
   * Space complexity: O(1)
   *
   * @param {*} val - value added to queue
   * @return {Number} - size of queue after value inserted
   */
  enqueue(val) {
    if (this.size >= this.capacity) { return; }

    const node = new Node(val);
    this.size++;

    // if queue was empty
    if (this.front === null) {
      this.front = this.rear = node;
      return this.size;
    }

    this.rear.next = node;
    this.rear = this.rear.next;
    return this.size;
  }

  /**
   * Description: Remove node from front of queue
   * Strategy: Reassign front to next node
   *
   * Time complexity: O(1)
   * Space complexity: O(1)
   *
   * @return {*} - value removed from queue, or undefined if empty
   */
  dequeue() {
    if (this.size === 0) { return; }

    const value = this.front.value;
    this.front = this.front.next;
    this.size--;
    return value;
  }

  /**
   * Description: Check size of queue
   * Strategy: Use size property
   *
   * Time complexity: O(1)
   * Space complexity: O(1)
   *
   * @return {Number} - total amount of items in queue
   */
  getSize() {
    return this.size;
  }
}

module.exports = Queue;

@@ -571,33 +571,32 @@
 city;%0A  %7D%0A%0A  /**
- 
 %0A   * Descriptio
@@ -602,64 +602,82 @@
 on: 
-Check if queue is empty%0A   * Strategy: Use size property
+Remove node from front of queue%0A   * Strategy: Reassign front to next node
 %0A   
@@ -756,349 +756,76 @@
 rn %7B
-Boolean%7D - true if empty, or false otherwise%0A   */%0A  isEmpty() %7B%0A    return this.size === 0;%0A  %7D%0A%0A  /** %0A   * Description: Check if queue has reached capacity%0A   * Strategy: Check if size equals capacity%0A   *%0A   * Time complexity: O(1)%0A   * Space complexity: O(1)
+*%7D - value removed from queue, or undefined if empty
 %0A   *
+/
 %0A  
- * @return %7BBoolean%7D - true if full, or false otherwise%0A   */%0A  isFull
+dequeue
 () %7B
@@ -821,39 +821,36 @@
 dequeue() %7B%0A    
-return 
+if (
 this.size === th
@@ -851,302 +851,128 @@
 === 
-this.capacity;%0A  %7D%0A%0A  /**%0A   * Description: View value at front of que
+0) %7B return; %7D%0A%0A    const value = this.front.val
 ue
+;
 %0A   
-* Strategy: Look at front property%0A   *%0A   * Time complexity: O(1)%0A   * Space complexity: O(1)%0A   *%0A   * @return %7B*%7D - value at front of queue%0A   */%0A  peek() %7B
+ this.front = this.front.next;
 %0A    
-if (
 this.
-front !== null) %7B return this.front.
+size--;%0A    return 
 value;
- %7D;
 %0A  %7D
@@ -1604,32 +1604,33 @@
 size;%0A  %7D%0A%0A  /**
+ 
 %0A   * Descriptio
@@ -1636,82 +1636,64 @@
 on: 
-Remove node from front of queue%0A   * Strategy: Reassign front to next node
+Check if queue is empty%0A   * Strategy: Use size property
 %0A   
@@ -1772,76 +1772,349 @@
 rn %7B
-*%7D - value removed from queue, or undefined if empty
+Boolean%7D - true if empty, or false otherwise%0A   */%0A  isEmpty() %7B%0A    return this.size === 0;%0A  %7D%0A%0A  /** %0A   * Description: Check if queue has reached capacity%0A   * Strategy: Check if size equals capacity%0A   *%0A   * Time complexity: O(1)%0A   * Space complexity: O(1)
 %0A   *
-/
 %0A  
-dequeue
+ * @return %7BBoolean%7D - true if full, or false otherwise%0A   */%0A  isFull
 () %7B
@@ -2110,36 +2110,39 @@
  isFull() %7B%0A    
-if (
+return 
 this.size === 0)
@@ -2143,128 +2143,302 @@
 === 
-0) %7B return; %7D%0A%0A    const value = this.front.val
+this.capacity;%0A  %7D%0A%0A  /**%0A   * Description: View value at front of que
 ue
-;
 %0A   
- this.front = this.front.next;
+* Strategy: Look at front property%0A   *%0A   * Time complexity: O(1)%0A   * Space complexity: O(1)%0A   *%0A   * @return %7B*%7D - value at front of queue%0A   */%0A  peek() %7B
 %0A    
+if (
 this.
-size--;%0A    return 
+front !== null) %7B return this.front.
 value;
+ %7D;
 %0A  %7D

add Queue with dequeue, enqueue, isEmpty, isFull, peek and getSize methods