Data Structure : remove live code & console.log

This commit is contained in:
Eric Lavault
2021-10-10 16:11:06 +02:00
parent 30779682b9
commit a3d44ad3e1
8 changed files with 32 additions and 153 deletions

View File

@ -45,28 +45,14 @@ const Stack = (function () {
}
// To see all the elements in the stack
Stack.prototype.view = function () {
for (let i = 0; i < this.top; i++) { console.log(this.stack[i]) }
Stack.prototype.view = function (output = value => console.log(value)) {
for (let i = 0; i < this.top; i++) {
output(this.stack[i])
}
}
return Stack
}())
// Implementation
const myStack = new Stack()
myStack.push(1)
myStack.push(5)
myStack.push(76)
myStack.push(69)
myStack.push(32)
myStack.push(54)
console.log(myStack.size())
console.log(myStack.peek())
console.log(myStack.pop())
console.log(myStack.peek())
console.log(myStack.pop())
console.log(myStack.peek())
myStack.push(55)
console.log(myStack.peek())
myStack.view()
export { Stack }