Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to remove an element from the front of the dequeue.
DSA Javascript
function dequeueFront(queue) {
if (queue.length === 0) return null;
return queue.[1]();
}Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() removes from the end, not the front.
Using push() or unshift() adds elements instead of removing.
✗ Incorrect
The shift() method removes the first element from an array, which matches removing from the front of a dequeue.
2fill in blank
mediumComplete the code to remove an element from the rear of the dequeue.
DSA Javascript
function dequeueRear(queue) {
if (queue.length === 0) return null;
return queue.[1]();
}Attempts:
3 left
💡 Hint
Common Mistakes
Using shift() removes from the front, not the rear.
Using push() or unshift() adds elements instead of removing.
✗ Incorrect
The pop() method removes the last element from an array, which matches removing from the rear of a dequeue.
3fill in blank
hardFix the error in the dequeueFront function to correctly remove from the front.
DSA Javascript
function dequeueFront(queue) {
if (queue.length === 0) return null;
return queue.[1]();
}Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() instead of shift().
Trying to use push() or unshift() which add elements.
✗ Incorrect
shift() correctly removes the first element; pop() removes the last, which is incorrect here.
4fill in blank
hardFill both blanks to remove from front and rear correctly.
DSA Javascript
function removeFromDequeue(queue, fromFront) {
if (queue.length === 0) return null;
if (fromFront) {
return queue.[1]();
} else {
return queue.[2]();
}
}Attempts:
3 left
💡 Hint
Common Mistakes
Swapping shift() and pop() usage.
Using push() or unshift() which add elements.
✗ Incorrect
shift() removes from front, pop() removes from rear, matching the function's logic.
5fill in blank
hardFill both blanks to create a function that removes from front or rear and returns the updated queue.
DSA Javascript
function dequeueOperation(queue, removeFront) {
if (queue.length === 0) return queue;
if (removeFront) {
queue.[1]();
} else {
queue.[2]();
}
return queue;
}Attempts:
3 left
💡 Hint
Common Mistakes
Adding a semicolon after return queue causing syntax issues.
Using push() or unshift() instead of shift() or pop().
✗ Incorrect
shift() removes front, pop() removes rear, and returning queue without extra semicolon is correct syntax.
