A simple queue implementation for JavaScript, allows to easily create a new queue, add and remove ietems from the queue, quickly view items and get the queue size.
Include the Queue.min.js
in your HTML before the closing </body>
tag
<script src="src/Queue.min.js"></script>
now create a new Queue
var myQ = new Queue([1,2,3,4]);
myQ.add('new item to add');
.next()
removes and returns the item from the front of the Queue
myQ.next();
//returns 1
myQ.next();
//now returns 2
myQ.getLength();
myQ.isEmpty();
returns a boolean true
if the Queue is empty else false
//view the item in front
myQ.peek();
//view the second item in the Queue
myQ.peek(1);
//view the third item in the Queue
myQ.peek(2);
//view the item in front
myQ.clear();