Complete the code to add an element to the end of the queue.
enqueue(element) {
this.items.[1](element);
}The push method adds an element to the end of the array, which is how we add to the queue.
Complete the code to remove an element from the front of the queue.
dequeue() {
return this.items.[1]();
}The shift method removes and returns the first element of the array, which matches removing from the front of the queue.
Fix the error in the code to check if the queue is empty.
isEmpty() {
return this.items.length [1] 0;
}To check if the queue is empty, we compare length to 0 using == or ===. Using = is assignment, not comparison.
Fill in the blank to return the front element without removing it.
front() {
if (this.isEmpty()) {
return undefined;
}
return this.items[[1]];
}The front element of the queue is at index 0 in the array.
Fill in the blanks to return the size of the queue and clear it.
size() {
return this.items.[1];
}
clear() {
this.items = [2];
}The size of the queue is the length of the array. To clear, assign an empty array [].
