Complete the code to assign a delivery agent to an order.
order.assignAgent([1])The assignAgent method requires the delivery agent object to assign it to the order.
Complete the code to check if the delivery agent is available before assignment.
if (agent.[1]()) { order.assignAgent(agent); }
isBusy() which returns the opposite.The isAvailable() method checks if the agent is free to take a new delivery.
Fix the error in the code to update the agent's status after assignment.
agent.[1] = false;The available property should be set to false to mark the agent as busy.
Fill both blanks to create a function that assigns the first available agent from a list.
function assignFirstAvailableAgent(order, agents) {
for (let [1] of agents) {
if ([2].isAvailable()) {
order.assignAgent([2]);
break;
}
}
}The loop variable should be agent to represent each delivery agent in the list. The same variable is used to check availability and assign.
Fill all three blanks to implement a method that returns a list of available agents.
function getAvailableAgents([1]) { return [2].filter([3] => [3].isAvailable()); }
The parameter and the array to filter are both agents. The filter callback uses agent as the variable representing each element.