• function Queue() {
      let first = null;
      
      const push = function(value) {
        const newNode = new Node(value);
        newNode.next = first;
        first = newNode;
      }
      
      const get = function() {
        const firstNode = first;
    
        if(getIsEmpty()) {
          throw new Error('Queue is empty');
        }
    
        first = firstNode.next;
        return firstNode.value;
      }
      
      const getIsEmpty = function() {
        return first === null
      }
    
      return {
        push,
        get,
        getIsEmpty
      }
    }
    Edited by Anton Orel
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment