Skip to content

Instantly share code, notes, and snippets.

@o-henry
Created February 26, 2020 02:03
Show Gist options
  • Save o-henry/c9721f5aab3a7e6e8ac466a3df50c26f to your computer and use it in GitHub Desktop.
Save o-henry/c9721f5aab3a7e6e8ac466a3df50c26f to your computer and use it in GitHub Desktop.
Stack
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