Data Structures - Create a Doubly Linked List

Tell us what’s happening:

This exercise seems to be broken.

None of the tests pass successful. Even the marked solution on the forum won’t pass.

What’s curious, the first test should always pass as this is part of the code we shouldn’t touch at all, isn’t it?

Your code so far

var Node = function(data, prev) {
  this.data = data;
  this.prev = prev;
  this.next = null;
};
var DoublyLinkedList = function() {
  this.head = null;
  this.tail = null;
  // Only change code below this line
  this.add = function (data) {
    let node = new Node(data, this.tail);
    if (!this.head) {
      this.head = node;
      this.tail = node;
    } else {
      let tempNode = this.tail;
      tempNode.next = node;
      this.tail = node;
    }
  };

  this.remove = function (data) {
    if (this.head === null) return null;
    let tempNode = this.head;
    while (tempNode !== this.tail) {
      if (tempNode.data === data) {
        if (tempNode === this.head) {
          this.head = tempNode.next;
          tempNode.next.prev = null;
        } else {
          let prevNode = tempNode.prev;
          prevNode.next = tempNode.next;
        }
      }
      tempNode = tempNode.next;
    }
    if (tempNode.data === data) {
      this.tail = tempNode.prev;
      tempNode.prev.next = null;
    }
  };
  // Only change code above this line
};


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36

Challenge Information:

Data Structures - Create a Doubly Linked List

Hi I’M Prince and I’m currently building more skills here on freecodecamp from Ghana

Please do not reply to someone else’s topic if you have nothing to say about the question they asked.

This is not true actually. The test may or may not be checking for something that you need to write still.

Okay please , I first didn’t know where I would post my introduction as i just started, so sorry :folded_hands:

I think I agree.
The tests are not working.
You can open a github issue for further investigation.

Bugs can be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.

If you change:

var Node = function(data, prev) {

to

function Node(data, prev) {

and

var DoublyLinkedList = function() {

to

function DoublyLinkedList() {

tests will pass. But yes, there’s something not right, as your original version also should pass.

Thank you both @hbar1st and @sanity

As suggested I opened an issue over at github as it seems this one hasn’t been reported yet. Thanks to sanity I could at least work around with the more modern rewrite of the functions.

What’s curious is, this was part of the code which should’ve been checked that there were no changes made.