@violangreg/

Stack as an array

Nodejs

No description

fork
loading
Files
  • index.js
index.js
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
class Stack {
  constructor(){
    this.arr = [];
  }
  peek() {
    return this.arr[this.arr.length-1];
  }
  push(value){
    this.arr.push(value);
    return this;
  }
  pop(){
    this.arr.pop();

    return this;
  }

}

const myStack = new Stack();
myStack.push("google");
myStack.push("Udemy");
myStack.push("Discord");
myStack.peek();
myStack.pop();



//Discord
//Udemy
//google
node v10.16.0