mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 17:50:39 +08:00
Data Structure : remove live code & console.log
This commit is contained in:
@ -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 }
|
||||
|
@ -53,16 +53,5 @@ class Stack {
|
||||
return el instanceof Stack
|
||||
}
|
||||
}
|
||||
const newStack = new Stack()
|
||||
console.log('Is it a Stack?,', Stack.isStack(newStack))
|
||||
console.log('Is stack empty? ', newStack.isEmpty)
|
||||
newStack.push('Hello world')
|
||||
newStack.push(42)
|
||||
newStack.push({ a: 6, b: 7 })
|
||||
console.log('The length of stack is ', newStack.length)
|
||||
console.log('Is stack empty? ', newStack.isEmpty)
|
||||
console.log('Give me the last one ', newStack.last)
|
||||
console.log('Pop the latest ', newStack.pop())
|
||||
console.log('Pop the latest ', newStack.pop())
|
||||
console.log('Pop the latest ', newStack.pop())
|
||||
console.log('Is stack empty? ', newStack.isEmpty)
|
||||
|
||||
export { Stack }
|
||||
|
Reference in New Issue
Block a user