MCPcopy Create free account
hub / github.com/betomoedano/JavaScript-Coding-Interview-Questions / Stack

Class Stack

stacks/queue-via-stacks.js:39–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37}
38
39class Stack {
40 constructor() {
41 this.data = [];
42 }
43 size() {
44 return this.data.length;
45 }
46 isEmpty() {
47 return this.size() === 0;
48 }
49 push(value) {
50 this.data.push(value);
51 }
52 pop() {
53 return this.data.pop();
54 }
55 peek() {
56 if (this.isEmpty()) return null;
57 return this.data[this.size() - 1];
58 }
59}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected