Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

147
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda