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

Method removeAt

chapter07/util/LinkedList.js:68–89  ·  view source on GitHub ↗
(index)

Source from the content-addressed store, hash-verified

66 }
67
68 removeAt(index) {
69 let i = 0;
70 let cur = this.head;
71 let prev = null;
72
73 while (cur != null) {
74 if (i == index) {
75 // remove
76 if (prev == null)
77 this.head = cur.next;
78 else prev.next = cur.next;
79 cur.next = null;
80 return cur.value;
81 }
82 else {
83 prev = cur;
84 cur = cur.next;
85 i++;
86 }
87 }
88 return null;
89 }
90
91 insertAt(index, value) {
92 if (index == 0) return this.prepend(value);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected