Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let ml = {
- push( k ) {
- this.begin = { key: k, next: this.begin }
- },
- pop() {
- if (this.begin) {
- let rv = this.begin
- this.begin = this.begin.next
- return rv.key
- }
- },
- forEach( f ) {
- let e = this.begin, i = 0
- while (e) {
- f( e.key, i++, e )
- e = e.next
- }
- }
- }
- ml.push(6)
- ml.push(4)
- ml.push(3)
- ml.push(7)
- ml.pop()
- ml.forEach( v => console.log(v) )
- console.log(
- JSON.stringify(ml)
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement