Interview Question 11 | JavaScript Pro | @codeDynasty-O95
This code snippet represents a simplified scenario where there is a list of waiting cars and a list of serviced cars. The `moveNextCar` function is used to move the next car from the waiting list to the serviced list.
Here's a step-by-step breakdown of what the code does:
1. The initial waiting car list is defined as an array of car brands: ["Ford", "Jaguar", "Audi", "Jeep", "Mercedes"].
2. The serviced car list is initially an empty array.
3. The `moveNextCar` function is defined with two parameters: `waitingList` and `servicedList`.
4. Inside the `moveNextCar` function:
a. The first car in the waiting list is removed using the `shift()` method and assigned to the `car` variable.
b. The `car` is then added to the end of the serviced list using the `push()` method.
c. The waiting list and serviced list are updated with the modified arrays.
d. Finally, an object with the updated waiting list and serviced list is returned.
5. The `moveNextCar` function is called with the initial waiting list (`waitingCarList`) and serviced list (`servicedCarList`) as arguments.
6. The returned object from `moveNextCar` is destructured to obtain the updated waiting list (`waitingList`) and serviced list (`servicedList`).
7. The console.log statement is used to print the updated waiting list and serviced list.
The output of the code will be:
```
Waiting car list: Jaguar, Audi, Jeep, Mercedes
Serviced car List: Ford
```
The first car "Ford" is moved from the waiting list to the serviced list, resulting in the updated waiting list and serviced list as shown in the output.