MCPcopy Create free account
hub / github.com/careercup/CtCI-6th-Edition-JavaScript / removeAt

Method removeAt

chapter02/util/LinkedListX.js:81–102  ·  view source on GitHub ↗
(index)

Source from the content-addressed store, hash-verified

79 }
80
81 removeAt(index) {
82 let i = 0;
83 let cur = this.head;
84 let prev = null;
85
86 while (cur != null) {
87 if (i == index) {
88 // remove
89 if (prev == null)
90 this.head = cur.next;
91 else prev.next = cur.next;
92 cur.next = null;
93 return cur.value;
94 }
95 else {
96 prev = cur;
97 cur = cur.next;
98 i++;
99 }
100 }
101 return null;
102 }
103
104 insertAt(index, value) {
105 if (index == 0) return this.prepend(value);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected