Created
January 31, 2017 13:59
-
-
Save gerrard00/d60e7fb4bf0ef8a46d1f4eb492c04080 to your computer and use it in GitHub Desktop.
Simple javascript queue implementation for several test projects.
This file contains 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
'use strict'; | |
function Queue() { | |
return { | |
entries: [], | |
enqueue(value) { | |
this.entries.push(value); | |
}, | |
dequeue() { | |
return this.entries.shift(); | |
}, | |
}; | |
} | |
const q = new Queue(); | |
q.enqueue(8); | |
q.enqueue(6); | |
q.enqueue(7); | |
console.log(`+${q.dequeue()}`); | |
q.enqueue(5); | |
let current; | |
while (current = q.dequeue()) { | |
console.log(`-${current}`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment