Published
Edited
Jun 19, 2018
Insert cell
Insert cell
stackOperations = ({
enumerate: function(){
var output = '';
for(let i = this.length; i > -1; i--){
output = output ? output + ', ' + this[i] : this[i]
}
return output
},
push: function(i) {
this.push(i);
},
pop: function() {
return this.pop();
},
pick: function(){
return this[this.length - 1];
}
})
Insert cell
assignOpsToStack = function assignOpsToStack( stack ) {
var stackObject = {};
Object.keys(stackOperations).forEach(function(operation){
stackObject[operation] = stackOperations[operation].bind( stack );
});
return stackObject;
}
Insert cell
Stack = function Stack() {
var stack = new Array;
return assignOpsToStack( stack );
}
Insert cell
stack = new Stack
Insert cell
log = {
stack.push(1)
stack.push(2)
stack.push(22)
stack.push(111)
return stack.enumerate()
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more