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

Class Stack

chapter03/util/Stack.js:12–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10- size()
11*/
12class Stack {
13 constructor() {
14 this._data = [];
15 }
16
17 size() {
18 return this._data.length;
19 }
20
21 isEmpty() {
22 return this.size() == 0;
23 }
24
25 push(value) {
26 this._data.push(value);
27 }
28
29 pop() {
30 return this._data.pop();
31 }
32
33 peek() {
34 if (this.isEmpty()) return null;
35 return this._data[this.size() - 1];
36 }
37
38 _toArray() {
39 return this._data;
40 }
41}
42
43module.exports = Stack;
44

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected