Skip to content

Instantly share code, notes, and snippets.

Created March 30, 2016 09:00
Show Gist options
  • Save anonymous/d1610efada3aa5e9a2aaa42d35d7d916 to your computer and use it in GitHub Desktop.
Save anonymous/d1610efada3aa5e9a2aaa42d35d7d916 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/kokoxe
<!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">
function Stack() {
this.items = [];
this.top = -1;
}
Stack.prototype.push = function(val) {
this.items.push(val);
this.top++;
}
Stack.prototype.pop = function() {
if(this.top >= 0) {
this.top--;
return this.items.pop();
}
else {
throw 'Nothing to pop';
}
}
Stack.prototype.display = function() {
console.log.apply(null, this.items);
}
s = new Stack();
s.push(3);
s.push(4);
s.display();
</script>
<script id="jsbin-source-javascript" type="text/javascript">function Stack() {
this.items = [];
this.top = -1;
}
Stack.prototype.push = function(val) {
this.items.push(val);
this.top++;
}
Stack.prototype.pop = function() {
if(this.top >= 0) {
this.top--;
return this.items.pop();
}
else {
throw 'Nothing to pop';
}
}
Stack.prototype.display = function() {
console.log.apply(null, this.items);
}
s = new Stack();
s.push(3);
s.push(4);
s.display();
</script></body>
</html>
function Stack() {
this.items = [];
this.top = -1;
}
Stack.prototype.push = function(val) {
this.items.push(val);
this.top++;
}
Stack.prototype.pop = function() {
if(this.top >= 0) {
this.top--;
return this.items.pop();
}
else {
throw 'Nothing to pop';
}
}
Stack.prototype.display = function() {
console.log.apply(null, this.items);
}
s = new Stack();
s.push(3);
s.push(4);
s.display();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment