Created
March 30, 2016 09:00
-
-
Save anonymous/d1610efada3aa5e9a2aaa42d35d7d916 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/kokoxe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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