Skip to content

Instantly share code, notes, and snippets.

@injust90
Created March 2, 2020 16:09
Show Gist options
  • Save injust90/bbadb370573293716ecdebed528e26a9 to your computer and use it in GitHub Desktop.
Save injust90/bbadb370573293716ecdebed528e26a9 to your computer and use it in GitHub Desktop.
class Stack {
constructor () {
this.storage = {}
this.size = 0
}
push(element) {
this.size++
this.storage[this.size] = element
}
pop() {
let removed = this.storage[this.size]
delete this.storage[this.size]
this.size--
return removed
}
peek() {
return this.storage[this.size]
}
}
const stack = new Stack()
stack.push('dog')
stack.push('cat')
stack.push('bear')
stack.pop()
stack.peek()
@injust90
Copy link
Author

injust90 commented Mar 2, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment