Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
How does this enqueue method work in Queue?
class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class Queue {
  constructor() {
    this.first = null;
    this.last = null;
    this.length = 0;
  }

  enqueue(value) {
    const newNode = new Node(value);
    if(this.length === 0){ 
      this.first = newNode;
      this.last = newNode;
    }else{ 
    // How these two lines can create nested object?
    this.last.next = newNode;
    this.last = newNode;
    }
    this.length++;
  }
}

const myQueue = new Queue();

myQueue.enqueue('Joy');
...
myQueue.enqueue('Samir');

// Output this.first
{
    value: "Joy",
    next: {
      value: "Matt",
      next: {
        value: "Pavel",
        next: {
          value: "Samir",
          next: null,
        },
      },
    },
  };

Those two lines confused me a lot and I didn't understand them. Since I understand dequeue method, I have removed its code. I would appreciate it if someone could explain this to me.

Because I had put my whole code for better understanding, I have repeated these lines. I had put my whole code for better understanding, I have repeated these lines. Because I had put my whole code for better understanding, I have repeated these lines. Because I had put my whole code for better understanding, I have repeated these lines

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!