Skip to content

Instantly share code, notes, and snippets.

@timotew
Created June 5, 2021 11:39
Show Gist options
  • Select an option

  • Save timotew/cc1c65b7fa0ac81e3f31b90f06ecce25 to your computer and use it in GitHub Desktop.

Select an option

Save timotew/cc1c65b7fa0ac81e3f31b90f06ecce25 to your computer and use it in GitHub Desktop.

Revisions

  1. timotew created this gist Jun 5, 2021.
    26 changes: 26 additions & 0 deletions queue-js.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    function q() { //FIFo

    var arr = [3,6,7];

    return {
    enqueue: data => {
    arr.unshift(data);
    },
    dequeue: () => {
    return arr.pop();
    },
    peek: () => {
    if (arr.length === 0){
    return null;
    }

    return arr[arr.length - 1];
    }
    }
    };

    var queue = new q();

    console.log(queue.peek());
    console.log(queue.dequeue());
    console.log(queue.peek());