Created
February 26, 2020 02:03
-
-
Save o-henry/c9721f5aab3a7e6e8ac466a3df50c26f to your computer and use it in GitHub Desktop.
Stack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stack { | |
constructor() { | |
this._arr = []; | |
} | |
push(item) { | |
this._arr.push(item); | |
} | |
pop() { | |
return this._arr.pop(); | |
} | |
peek() { | |
return this._arr[this._arr.length - 1]; | |
} | |
} | |
const stack = new Stack(); | |
stack.push(1); | |
stack.push(2); | |
stack.push(3); | |
stack.pop(); // 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment