Complete the code to add an element to the end of the queue.
queue.[1](element);In JavaScript, to add an element at the end of an array (used as a queue), we use push.
Complete the code to check if the queue is empty before enqueueing.
if (queue.[1] === 0) { console.log('Queue is empty'); }
The length property gives the number of elements in an array in JavaScript.
Fix the error in the enqueue function to correctly add an element.
function enqueue(queue, element) { queue.[1](element); return queue; }The push method adds an element to the end of the array, which is the correct enqueue operation.
Fill both blanks to create a function that enqueues an element and returns the new queue length.
function enqueue(queue, element) {
queue.[1](element);
return queue.[2];
}The push method adds the element, and length returns the new size of the queue.
Fill all three blanks to enqueue an element only if the queue size is less than maxSize.
function enqueue(queue, element, maxSize) {
if (queue.[1] < maxSize) {
queue.[2](element);
return queue.[3];
} else {
return 'Queue full';
}
}Check the queue size with length, add element with push, and return the new size with length.
