Advertisement
tomuwhu

verem

Feb 20th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let ml = {
  2.     push( k ) {
  3.         this.begin = { key: k, next: this.begin }
  4.     },
  5.     pop() {
  6.         if (this.begin) {
  7.             let rv = this.begin
  8.             this.begin = this.begin.next
  9.             return rv.key
  10.         }
  11.     },
  12.     forEach( f ) {
  13.         let e = this.begin, i = 0
  14.         while (e) {
  15.             f( e.key, i++, e )
  16.             e = e.next
  17.         }
  18.     }
  19. }
  20.  
  21. ml.push(6)
  22. ml.push(4)
  23. ml.push(3)
  24. ml.push(7)
  25.  
  26. ml.pop()
  27.  
  28. ml.forEach( v => console.log(v) )
  29.  
  30. console.log(
  31.     JSON.stringify(ml)
  32. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement