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

145
Views
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
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!