fix(curriculum): repair failing tests for doubly linked list challenge (#66965)

This commit is contained in:
Ayush Kumar Singh
2026-04-20 13:35:54 +05:30
committed by GitHub
parent 983b249de0
commit 25d3079089

View File

@@ -94,7 +94,13 @@ assert(
test.add(5);
test.add(6);
test.add(723);
return test.print().join('') == '56723';
var result = [];
var curr = test.head;
while (curr) {
result.push(curr.data);
curr = curr.next;
}
return result.join('') == '56723';
})()
);
```
@@ -111,7 +117,13 @@ assert(
test.add(50);
test.add(68);
test.add(73);
return test.printReverse().join('') == '736850';
var result = [];
var curr = test.tail;
while (curr) {
result.push(curr.data);
curr = curr.prev;
}
return result.join('') == '736850';
})()
);
```
@@ -129,7 +141,13 @@ assert(
test.add(35);
test.add(60);
test.remove(25);
return test.print().join('') == '3560';
var result = [];
var curr = test.head;
while (curr) {
result.push(curr.data);
curr = curr.next;
}
return result.join('') == '3560';
})()
);
```
@@ -147,48 +165,17 @@ assert(
test.add(35);
test.add(60);
test.remove(60);
return test.print().join('') == '2535';
var result = [];
var curr = test.head;
while (curr) {
result.push(curr.data);
curr = curr.next;
}
return result.join('') == '2535';
})()
);
```
# --before-each--
```js
DoublyLinkedList.prototype = Object.assign(
DoublyLinkedList.prototype,
{
print() {
if (this.head == null) {
return null;
} else {
var result = new Array();
var node = this.head;
while (node.next != null) {
result.push(node.data);
node = node.next;
};
result.push(node.data);
return result;
};
},
printReverse() {
if (this.tail == null) {
return null;
} else {
var result = new Array();
var node = this.tail;
while (node.prev != null) {
result.push(node.data);
node = node.prev;
};
result.push(node.data);
return result;
};
}
});
```
# --seed--