-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
35 lines (30 loc) · 928 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// reads through our list and removes desired node in the Linked List
async remove(index) {
const currNode = await this.get(index);
const prevNode = await this.get(index - 1);
// If index not in LL, return false
if (currNode === false) {
return false;
}
// If removing the head, reassign the head to the next node
if (index === 0) {
await this.setHead(currNode.next);
// If removing the tail, reassign the tail to the prevNode
} else if (currNode.next === null) {
await this.setTail(prevNode._id);
await this.col.updateOne(
{ _id: prevNode._id },
{ $set: { next: currNode.next } }
);
// Happy Path
} else {
await this.col.updateOne(
{ _id: prevNode._id },
{ $set: { next: currNode.next } }
);
}
await this.col.deleteOne({
_id: currNode._id,
});
return true;
}