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

271
Views
Enqueue method not acting how it should

I'm looking at Colt Steele's enqueue method from his udemy class. When I create a new queue based on his code and console.log it, it shows that the the first property is continuously being updated, but by the code, it seems like it should only get updated when first equals null. So shouldn't it only get updated once?

Then, the last property's next property is updated to newNode, but after that, the last property is then updated to newNode, so wouldn't that cancel out the previous command? Wouldn't it add a new Node to the last's next property, and wouldn't that next property get reassigned to null by the next command when we then make the last property equal to the newNode?

function Queue(){
this.first = null;
this.last = null;
this.size = 0;
}

function Node(value){
  this.value = value;
  this.next = null;
}

Queue.prototype.enqueue = function(value){
  let newNode = new Node(value);
  if(!this.first){
    this.first = newNode;
    this.last = newNode;
  }
  else {
    this.last.next = newNode;
    this.last = newNode;
  }
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!