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

Method insertAt

chapter07/util/LinkedList.js:91–109  ·  view source on GitHub ↗
(index, value)

Source from the content-addressed store, hash-verified

89 }
90
91 insertAt(index, value) {
92 if (index == 0) return this.prepend(value);
93 let cur = this.head;
94 let i = 0;
95
96 while (cur != null) {
97 if (i == index - 1) {
98 let node = new Node(value);
99 node.next = cur.next;
100 cur.next = node;
101 return true;
102 }
103 else {
104 i++;
105 cur = cur.next;
106 }
107 }
108 return false;
109 }
110
111 tail() {
112 return this.tail;

Callers

nothing calls this directly

Calls 1

prependMethod · 0.95

Tested by

no test coverage detected