Skip to content

Instantly share code, notes, and snippets.

@kyleshevlin
Created June 20, 2017 06:10
Show Gist options
  • Save kyleshevlin/c551970c10f44e23c302baa1f36a5466 to your computer and use it in GitHub Desktop.
Save kyleshevlin/c551970c10f44e23c302baa1f36a5466 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/yumoyat
<!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';
function Stack() {
this.storage = '';
}
Stack.prototype.push = function (val) {
if (this.storage.length === 0) {
this.storage = val;
} else {
this.storage = this.storage + '---' + val;
}
};
Stack.prototype.pop = function () {
var items = this.storage.split('---');
var val = items.pop();
this.storage = items.join('---');
return val;
};
Stack.prototype.size = function () {
return this.storage.split('---').length;
};
var myWeeklyMenu = new Stack();
myWeeklyMenu.push('Red Beans');
myWeeklyMenu.push('Ranch Skillet');
console.log(myWeeklyMenu.storage);
console.log(myWeeklyMenu.size());
var meal = myWeeklyMenu.pop();
console.log(meal);
</script>
<script id="jsbin-source-javascript" type="text/javascript">function Stack () {
this.storage = ''
}
Stack.prototype.push = function (val) {
if (this.storage.length === 0) {
this.storage = val
} else {
this.storage = this.storage + '---' + val
}
}
Stack.prototype.pop = function () {
const items = this.storage.split('---')
const val = items.pop()
this.storage = items.join('---')
return val
}
Stack.prototype.size = function () {
return this.storage.split('---').length
}
const myWeeklyMenu = new Stack()
myWeeklyMenu.push('Red Beans')
myWeeklyMenu.push('Ranch Skillet')
console.log(myWeeklyMenu.storage)
console.log(myWeeklyMenu.size())
const meal = myWeeklyMenu.pop()
console.log(meal);</script></body>
</html>
'use strict';
function Stack() {
this.storage = '';
}
Stack.prototype.push = function (val) {
if (this.storage.length === 0) {
this.storage = val;
} else {
this.storage = this.storage + '---' + val;
}
};
Stack.prototype.pop = function () {
var items = this.storage.split('---');
var val = items.pop();
this.storage = items.join('---');
return val;
};
Stack.prototype.size = function () {
return this.storage.split('---').length;
};
var myWeeklyMenu = new Stack();
myWeeklyMenu.push('Red Beans');
myWeeklyMenu.push('Ranch Skillet');
console.log(myWeeklyMenu.storage);
console.log(myWeeklyMenu.size());
var meal = myWeeklyMenu.pop();
console.log(meal);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment