-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (37 loc) · 670 Bytes
/
index.js
File metadata and controls
48 lines (37 loc) · 670 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// --- Directions
// Create a stack data structure. The stack
// should be a class with methods 'push', 'pop', and 'peek'
// Adding an element to the stack should store it until it is removed.
// --- Examples
// const s = new Stack();
// s.push(1);
// s.push(2);
// s.pop(); // return 2
// s.pop(); // return 1
/*
FILO
Stack Class
```
shift
unshift
push -> push
Array pop -> pop
splice
slice
```
*/
class Stack {
constructor() {
this.data = [];
}
push(record) {
this.data.push(record);
}
pop() {
return this.data.pop();
}
peek() {
return this.data[this.data.length - 1];
}
}
module.exports = Stack;