fa50eee2e718aead2d0f666d4d333416aebba3c4617ee68058ed81fcb5a824b3f120eff82f7d39c8eb86726c823fa8bd184dac9a7ad2882c47a286e1ec2981 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "use strict";
  2. exports.__esModule = true;
  3. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  4. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5. /**
  6. * @class Stack
  7. * @util
  8. */
  9. var Stack = function () {
  10. function Stack() {
  11. var initial = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  12. _classCallCheck(this, Stack);
  13. /**
  14. * Items collection.
  15. *
  16. * @type {Array}
  17. */
  18. this.items = initial;
  19. }
  20. /**
  21. * Add new item or items at the back of the stack.
  22. *
  23. * @param {*} items An item to add.
  24. */
  25. _createClass(Stack, [{
  26. key: "push",
  27. value: function push() {
  28. var _items;
  29. (_items = this.items).push.apply(_items, arguments);
  30. }
  31. /**
  32. * Remove the last element from the stack and returns it.
  33. *
  34. * @returns {*}
  35. */
  36. }, {
  37. key: "pop",
  38. value: function pop() {
  39. return this.items.pop();
  40. }
  41. /**
  42. * Return the last element from the stack (without modification stack).
  43. *
  44. * @returns {*}
  45. */
  46. }, {
  47. key: "peek",
  48. value: function peek() {
  49. return this.isEmpty() ? void 0 : this.items[this.items.length - 1];
  50. }
  51. /**
  52. * Check if the stack is empty.
  53. *
  54. * @returns {Boolean}
  55. */
  56. }, {
  57. key: "isEmpty",
  58. value: function isEmpty() {
  59. return !this.size();
  60. }
  61. /**
  62. * Return number of elements in the stack.
  63. *
  64. * @returns {Number}
  65. */
  66. }, {
  67. key: "size",
  68. value: function size() {
  69. return this.items.length;
  70. }
  71. }]);
  72. return Stack;
  73. }();
  74. exports.default = Stack;