mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-06 21:00:24 -04:00
fix(curriculum): repair failing tests for doubly linked list challenge (#66965)
This commit is contained in:
committed by
GitHub
parent
983b249de0
commit
25d3079089
@@ -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--
|
||||
|
||||
|
||||
Reference in New Issue
Block a user