Implement a queue data structure in JavaScript that contains the following operations:
Queue
Creates an instance of a Queue
class that doesn't contain any items. The constructor not accept any arguments.
enqueue
Adds an item to the back of the queue.
{*} item
: The item to be added to the back of the queue.{number}
: The new length of the queue.dequeue
Remove an item from the front of the queue.
{*} item
: The item at the front of the queue if it is not empty, undefined
otherwise.isEmpty
Determines if the queue is empty.
{boolean}
: true
if the queue has no items, false
otherwise.front
Returns the item at the front of the queue without removing it from the queue.
{*}
: The item at the front of the queue if it is not empty, undefined
otherwise.back
Returns the item at the back of the queue without removing it from the queue.
{*}
: The item at the back of the queue if it is not empty, undefined
otherwise.length
Returns the number of items in the queue.
{number}
: The number of items in the queue.const queue = new Queue();queue.isEmpty(); // truequeue.enqueue(1);queue.enqueue(2);queue.length(); // 2queue.enqueue(3);queue.front(); // 1queue.back(); // 3queue.dequeue(); // 1queue.isEmpty(); // false