queue data structure in javascript 2018
var Queue = (()=>{
const map = new WeakMap();
let _items = []
class Queue{
constructor(...items){
//initialize the items in queue
map.set(this, []);
_items = map.get(this);
// enqueuing the items passed to the constructor
this.enqueue(...items)
}
enqueue(...items){
//push items into the queue
this._items = [...this._items, ...items]
return this._items;
}
dequeue(count=1){
//pull out the first item from the queue
_items.splice(0,count);
return this._items;
}
peek(){
//peek at the first item from the queue
return _items[0]
}
size(){
//get the length of queue
return _items.length
}
isEmpty(){
//find whether the queue is empty or no
return _items.length===0
}
toArray(){
return _items
}
}
return Queue
})()
Also in JavaScript:
- Beautifule JS Console Log
- define a while loop in node js
- find key in nested json object
- moment.set
- binary to int javascript
- sql server import json
- unordered list in react native
- adding jquery to vuepress
- javascript click event notifications
- vue js link image link in props doesnt work
- parsing through json without using key value python
- comment dire le nombre de ligne html en cliquamt sur un boutton javascript
- lodash map
- javascript get element position relative to document
- change windlow location relitave to current one
- getcollectionnames
- classList has class
- c# get json object from the immediate window?
- month name array javascript
- how to check if object has key javascript
- javascript data em portugues
- app.js:19465 Uncaught TypeError: Cannot call a class as a function
- mongoose nullable
- downgrade angular version in project