Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

273
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda