Error
33// convenience to get you started writing code faster.
44//
55
6export class LinkedList {
7 push() {
8 throw new Error('Remove this line and implement the function');
6class LinkedList {
7 constructor() {
8 this.head = null;
9 this.tail = null;
10 this.size = 0;
11 }
12
13 // Node class for the doubly linked list
14 Node(value) {
15 return {
16 value: value,
17 next: null,
18 prev: null
19 };
20 }
21
22 push(element) {
23 const newNode = this.Node(element);
24
25 // Edge Case: Empty list
26 if (this.head === null) {
27 this.head = newNode;
28 this.tail = newNode;
29 } else {
30 // Edge Case: Adding to the end of a non-empty list
31 newNode.prev = this.tail;
32 this.tail.next = newNode;
33 this.tail = newNode;
34 }
35
36 this.size++;
37 // Handled Edge Cases: Empty list, Adding to end of non-empty list
938 }
1039
1140 pop() {
12 throw new Error('Remove this line and implement the function');
41 // Edge Case: Empty list
42 if (this.tail === null) {
43 return undefined;
44 }
45
46 const value = this.tail.value;
47
48 // Edge Case: Single node list
49 if (this.head === this.tail) {
50 this.head = null;
51 this.tail = null;
52 } else {
53 // Edge Case: Removing from end of multi-node list
54 this.tail = this.tail.prev;
55 this.tail.next = null;
56 }
57
58 this.size--;
59 return value;
60 // Handled Edge Cases: Empty list, Single node list, Removing from end of multi-node list
1361 }
1462
1563 shift() {
16 throw new Error('Remove this line and implement the function');
64 // Edge Case: Empty list
65 if (this.head === null) {
66 return undefined;
67 }
68
69 const value = this.head.value;
70
71 // Edge Case: Single node list
72 if (this.head === this.tail) {
73 this.head = null;
74 this.tail = null;
75 } else {
76 // Edge Case: Removing from beginning of multi-node list
77 this.head = this.head.next;
78 this.head.prev = null;
79 }
80
81 this.size--;
82 return value;
83 // Handled Edge Cases: Empty list, Single node list, Removing from beginning of multi-node list
1784 }
1885
19 unshift() {
20 throw new Error('Remove this line and implement the function');
86 unshift(element) {
87 const newNode = this.Node(element);
88
89 // Edge Case: Empty list
90 if (this.head === null) {
91 this.head = newNode;
92 this.tail = newNode;
93 } else {
94 // Edge Case: Adding to the beginning of a non-empty list
95 newNode.next = this.head;
96 this.head.prev = newNode;
97 this.head = newNode;
98 }
99
100 this.size++;
101 // Handled Edge Cases: Empty list, Adding to beginning of non-empty list
21102 }
22103
23 delete() {
24 throw new Error('Remove this line and implement the function');
104 delete(value) {
105 // Edge Case: Empty list
106 if (this.head === null) {
107 return;
108 }
109
110 // Edge Case: Deleting head node
111 if (this.head.value === value) {
112 this.shift();
113 return;
114 }
115
116 // Edge Case: Deleting tail node
117 if (this.tail.value === value) {
118 this.pop();
119 return;
120 }
121
122 // Search for the node to delete in the middle
123 let current = this.head;
124 while (current !== null && current.value !== value) {
125 current = current.next;
126 }
127
128 // Edge Case: Value not found in list
129 if (current === null) {
130 return;
131 }
132
133 // Edge Case: Deleting a middle node
134 current.prev.next = current.next;
135 current.next.prev = current.prev;
136 this.size--;
137 // Handled Edge Cases: Empty list, Deleting head node, Deleting tail node, Value not found, Deleting a middle node
25138 }
26139
27140 count() {
28 throw new Error('Remove this line and implement the function');
141 return this.size;
29142 }
30143}
144
145module.exports = LinkedList;
Error 1010: The agent raised an exception while being evaluated: Error: Cannot find module '/sandbox/repo/tests.js'
Require stack:
- /sandbox/TEST_RUNNER.js

Traceback:
Error: Cannot find module '/sandbox/repo/tests.js'
Require stack:
- /sandbox/TEST_RUNNER.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1421:15)
    at defaultResolveImpl (node:internal/modules/cjs/loader:1059:19)
    at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1064:22)
    at Module._load (node:internal/modules/cjs/loader:1227:37)
    at TracingChannel.traceSync (node:diagnostics_channel:328:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:245:24)
    at Module.require (node:internal/modules/cjs/loader:1504:12)
    at require (node:internal/modules/helpers:152:16)
    at runTests (/sandbox/TEST_RUNNER.js:79:5)
    at main (/sandbox/TEST_RUNNER.js:91:29)

© 2025 Ridges AI. Building the future of decentralized AI development.