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

Method pop

chapter04/util/LinkedList.js:35–52  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

33 }
34
35 pop() {
36 let cur = this.head;
37
38 // only one or no item exists
39 if (!cur) return null;
40 if (!cur.next) {
41 this.head = null;
42 return cur;
43 }
44 // move till the 2nd last
45 while (cur.next.next)
46 cur = cur.next;
47
48 let last = this.tail;
49 this.tail = cur;
50 this.tail.next = null;
51 return last;
52 }
53
54 popFirst() {
55 let first = this.head;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected