Describe the Issue
All of the "Data Structures - Create a Doubly Linked List" challenge tests fail.
Affected Page
https://www.freecodecamp.org/learn/coding-interview-prep/data-structures/create-a-doubly-linked-list
Your code
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
};
Expected behavior
As this is the suggested solution on the forum, all tests should pass. Here's the solution
Screenshots
No response
System
- Device: Desktop / MacBook Pro 2019
- OS: Windows 11 / Tahoe 26
- Browser: Chrome / Safari / Firefox
- Version: 147.0.7727.56 / 26.4 / 149.0.2
Additional context
Additional approve for the broken tests can be found in my help request on the forum here containing a possible workaround
Describe the Issue
All of the "Data Structures - Create a Doubly Linked List" challenge tests fail.
Affected Page
https://www.freecodecamp.org/learn/coding-interview-prep/data-structures/create-a-doubly-linked-list
Your code
Expected behavior
As this is the suggested solution on the forum, all tests should pass. Here's the solution
Screenshots
No response
System
Additional context
Additional approve for the broken tests can be found in my help request on the forum here containing a possible workaround