Advertisement
nikolayneykov

Untitled

May 22nd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let stack = (function () {
  2.   let data = []
  3.  
  4.   function push (el) {
  5.     data.push(el)
  6.   }
  7.  
  8.   function pop () {
  9.     let el = data.pop()
  10.     return el
  11.   }
  12.  
  13.   function peek () {
  14.     return data[data.length - 1]
  15.   }
  16.  
  17.   return { push, pop, peek }
  18. })()
  19.  
  20. stack.push(1)
  21. stack.push(2)
  22. stack.push(3)
  23. console.log(stack.peek())
  24. stack.pop()
  25. console.log(stack.peek())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement