Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class Stack {
- constructor(...items) {
- this._items = []
- items.forEach(item => this._items.push(item));
- }
- push(...items) {
- items.forEach(item => this._items.push(item));
- }
- pop() {
- if (this._items.length > 0)
- return this._items.pop();
- return null;
- }
- peek() {
- if (this._items.length > 0)
- return this._items[this._items.length - 1];
- return null;
- }
- size() {
- return this._items.length;
- }
- isEmpty() {
- return this.size() === 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement