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

146
Visualizações
Linked List implementation using Javascript

me and my partner have an issue. in the addToTail method we end by reassigning veryEndResult to newNode (veryEndResult = newNode).

What we were actually trying to do is reassign the value of veryEndResult (this.head.next) to newNode, is there a way to do this? We couldn't google it either because we don't really know how to go about forming that question.

Would love if an experienced coder could help us out on this.

class LinkedList {
  constructor () {
    this.head = null;
    this.length = 0;
  }
  
  addToHead (data) {
    const newNode = new LinkedListNode(data, this.head);
    this.head = newNode;
    this.length ++;
    return true;
  }

  addToTail (data) {
    const newNode = new LinkedListNode(data, null);
    let test = ['this','head'];
    this.length ++;
    for (let i = 0 ; i < this.length - 1 ; i++) {
      test.push('next');
    }
    let endResult = test.join('.');
    let veryEndResult = eval(endResult);
    console.log(endResult);
    veryEndResult = newNode;
  }
}
  
class LinkedListNode {
  constructor (value, next) {
    this.value = value;
    this.next = next;
  }
}

let linkedList = new LinkedList();

linkedList.addToHead(20);
linkedList.addToTail(30);
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