4 ms·
async function assignDriver(rider, availableDrivers) { const driverDistances = await calculateDistances(rider.location, availableDrivers); for
by kstenerud 2y ago
async function assignDriver(rider, availableDrivers) {
const driverDistances = await calculateDistances(rider.location, availableDrivers);
for (let driver of availableDrivers) {
if (driverDistances[driver.id] > 5) {
continue;
}
if (rider.preferredVehicle && rider.preferredVehicle !== driver.vehicle) {
continue;
}
if (driver.rating < 4.0) {
continue;
}
if (driver.rating >= 4.5 && rider.preferences.includes('Premium Driver') && !driver.isPremiumDriver) {
continue;
}
return driver;
}
return null;
}