Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Queue -> FIFO (FIRST IN FIRST OUT)
- function createQueue() {
- const queue = []
- return {
- enqueue: function(item){
- queue.unshift(item)
- },
- dequeue: function(item){
- queue.pop(item)
- },
- isEmpty: function(){
- return queue.length === 0
- },
- peek: function(){
- return queue[queue.length - 1]
- },
- length: function(){
- return queue.length
- }
- }
- }
- const q = createQueue()
- console.log(q.enqueue(1))
- console.log(q.length())
- console.log(q.enqueue(2))
- console.log(q.length())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement