Skip to content

Instantly share code, notes, and snippets.

@musale
Created June 1, 2017 09:51
Show Gist options
  • Save musale/140f0dcd845e6ad56cfc16ebdeaa6fa0 to your computer and use it in GitHub Desktop.
Save musale/140f0dcd845e6ad56cfc16ebdeaa6fa0 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/zenopub
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
"use strict";
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; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _items = Symbol();
var Stack = (function () {
function Stack() {
_classCallCheck(this, Stack);
this[_items] = [];
}
_createClass(Stack, [{
key: "push",
value: function push(element) {
this[_items].push(element);
}
}, {
key: "pop",
value: function pop() {
return this[_items].pop();
}
}, {
key: "peek",
value: function peek() {
return this[_items][this[_items].length - 1];
}
}, {
key: "isEmpty",
value: function isEmpty() {
return this[_items].length == 0;
}
}, {
key: "size",
value: function size() {
return this[_items].length;
}
}, {
key: "clear",
value: function clear() {
this[_items] = [];
}
}, {
key: "print",
value: function print() {
console.log(this.toString());
}
}, {
key: "toString",
value: function toString() {
return this[_items].toString();
}
}]);
return Stack;
})();
var s1 = new Stack();
s1.push(1);
s1.push(2);
s1.push(3);
s1.push(4);
s1.push(5);
console.log(s1.peek());
</script>
<script id="jsbin-source-javascript" type="text/javascript">let _items = Symbol();
class Stack {
constructor () {
this[_items] = [];
}
push(element){
this[_items].push(element);
}
pop(){
return this[_items].pop();
}
peek(){
return this[_items][this[_items].length-1];
}
isEmpty(){
return this[_items].length == 0;
}
size(){
return this[_items].length;
}
clear(){
this[_items] = [];
}
print(){
console.log(this.toString());
}
toString(){
return this[_items].toString();
}
}
let s1 = new Stack();
s1.push(1);
s1.push(2);
s1.push(3);
s1.push(4);
s1.push(5);
console.log(s1.peek());</script></body>
</html>
"use strict";
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; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _items = Symbol();
var Stack = (function () {
function Stack() {
_classCallCheck(this, Stack);
this[_items] = [];
}
_createClass(Stack, [{
key: "push",
value: function push(element) {
this[_items].push(element);
}
}, {
key: "pop",
value: function pop() {
return this[_items].pop();
}
}, {
key: "peek",
value: function peek() {
return this[_items][this[_items].length - 1];
}
}, {
key: "isEmpty",
value: function isEmpty() {
return this[_items].length == 0;
}
}, {
key: "size",
value: function size() {
return this[_items].length;
}
}, {
key: "clear",
value: function clear() {
this[_items] = [];
}
}, {
key: "print",
value: function print() {
console.log(this.toString());
}
}, {
key: "toString",
value: function toString() {
return this[_items].toString();
}
}]);
return Stack;
})();
var s1 = new Stack();
s1.push(1);
s1.push(2);
s1.push(3);
s1.push(4);
s1.push(5);
console.log(s1.peek());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment