Complete the code to initialize the queue with the root node.
const queue = [[1]];The queue should start with the root node to begin level order traversal.
Complete the code to remove the first node from the queue.
const current = queue.[1]();In level order traversal, we remove nodes from the front of the queue using shift().
Fix the error in adding the left child to the queue only if it exists.
if (current.left) queue.[1](current.left);
We add children to the end of the queue using push() to maintain BFS order.
Fill both blanks to add the right child to the queue only if it exists.
if (current.[1]) queue.[2](current.right);
Check if current.right exists, then add it to the queue with push().
Fill all three blanks to complete the while loop condition and add children to the queue.
while (queue.[1] > 0) { const current = queue.[2](); if (current.left) queue.[3](current.left); }
The loop runs while the queue has nodes (length > 0), removes the first node (shift()), and adds left child (push()).