Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. export class Stack {
  2. constructor(...items) {
  3. this._items = []
  4.  
  5. items.forEach(item => this._items.push(item));
  6. }
  7.  
  8. push(...items) {
  9. items.forEach(item => this._items.push(item));
  10. }
  11.  
  12. pop() {
  13. if (this._items.length > 0)
  14. return this._items.pop();
  15.  
  16. return null;
  17. }
  18.  
  19. peek() {
  20. if (this._items.length > 0)
  21. return this._items[this._items.length - 1];
  22.  
  23. return null;
  24. }
  25.  
  26. size() {
  27. return this._items.length;
  28. }
  29.  
  30. isEmpty() {
  31. return this.size() === 0;
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement