Complete the code to add an element to the front of the deque.
deque.[1](10);
The unshift method adds an element to the front of an array, which works as the front of the deque.
Complete the code to remove an element from the back of the deque.
let removed = deque.[1]();The pop method removes the last element from an array, which corresponds to the back of the deque.
Fix the error in the code to correctly add an element to the back of the deque.
deque.[1](20);
The push method adds an element to the end of the array, which is the back of the deque.
Fill both blanks to create a function that removes from front and adds to back of the deque.
function rotateDeque(deque) {
let front = deque.[1]();
deque.[2](front);
}The shift method removes the front element, and push adds it to the back, rotating the deque.
Fill all three blanks to create a function that adds to front, removes from back, and returns the removed element.
function addFrontRemoveBack(deque, value) {
deque.[1](value);
let removed = deque.[2]();
return removed;
}
let deque = [1, 2, 3];
let result = addFrontRemoveBack(deque, 0);
console.log(deque); // Output: [3]The function adds value to the front using unshift, removes the last element with pop, and returns it. The final deque after adding 0 to front and removing 3 from back is [0, 1, 2].
