Skip to content

Instantly share code, notes, and snippets.

@skrajewski
Last active March 18, 2021 13:24
Show Gist options
  • Save skrajewski/d33bfee3a1b31d0bb7c8ea42bcf113a6 to your computer and use it in GitHub Desktop.
Save skrajewski/d33bfee3a1b31d0bb7c8ea42bcf113a6 to your computer and use it in GitHub Desktop.

Revisions

  1. skrajewski revised this gist Mar 18, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion stack_example.js
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ class Stack {
    }

    pop() {
    this.stack.pop();
    return this.stack.pop();
    }
    }

  2. skrajewski created this gist Mar 18, 2021.
    17 changes: 17 additions & 0 deletions play.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    const stackA = new Stack();
    stackA.push("abc");
    stackA.push("xyz");
    console.log(stackA.stack);
    stackA.stack = [];
    console.log(stackA.stack);

    const stackB = createStack()
    stackB.push("abc");
    stackB.push("xyz");
    console.log(stackB.stack);
    stackB.stack = [];
    console.log(stackB.stack);
    console.log(stackB.pop());

    const stackC = createStack()
    console.log(stackC.pop());
    23 changes: 23 additions & 0 deletions stack_example.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    class Stack {
    constructor() {
    this.stack = [];
    }

    push(el) {
    this.stack.push(el);
    }

    pop() {
    this.stack.pop();
    }
    }

    const createStack = function () {
    const stack = [];
    const push = (el) => stack.push(el);
    const pop = () => stack.pop();

    return {
    push, pop
    };
    }