Created
February 12, 2020 16:41
-
-
Save Giagnus64/56f82846231728f8f281678945a5b23a to your computer and use it in GitHub Desktop.
Array implementation of a queue using unshift and pop
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
| // QUEUE = First In First Out | |
| const queue = []; | |
| queue.unshift("Resume.docx"); | |
| console.log(queue); | |
| //[ 'Resume.docx' ] | |
| queue.unshift("Data_Report.csv"); | |
| console.log(queue); | |
| //[ "Data_Report.csv", "Resume.docx" ] | |
| queue.unshift("Picture_of_Biscuit.png"); | |
| console.log(queue); | |
| //["Picture_of_Biscuit.png", "Data_Report.csv", "Resume.docx"] | |
| let firstOut = queue.pop(); | |
| //"Resume.docx" | |
| console.log(queue); | |
| //["Picture_of_Biscuit.png", "Data_Report.csv"] | |
| firstOut = queue.pop(); | |
| //"Data_report.csv" | |
| console.log(queue); | |
| //["Picture_of_Biscuit.png"]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment