Created
June 5, 2021 11:39
-
-
Save timotew/cc1c65b7fa0ac81e3f31b90f06ecce25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment