Created
March 2, 2020 16:09
-
-
Save injust90/bbadb370573293716ecdebed528e26a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: https://www.youtube.com/watch?v=1AJ4ldcH2t4