Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let stack = (function () {
- let data = []
- function push (el) {
- data.push(el)
- }
- function pop () {
- let el = data.pop()
- return el
- }
- function peek () {
- return data[data.length - 1]
- }
- return { push, pop, peek }
- })()
- stack.push(1)
- stack.push(2)
- stack.push(3)
- console.log(stack.peek())
- stack.pop()
- console.log(stack.peek())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement