Solución
solution.tsTypeScript
export function calculateTaxiFare(a: number, b: number, c: number): number {
const HOUR = b;
const PASSENGERS = c;
const BASE_FARE = 2.50;
const RATE_PER_KILOMETER = 1.20;
const NIGHT_SURCHARGE_MULTIPLIER = 1.5;
const EXTRA_PASSENGER_CHARGE = 0.30;
const INCLUDED_PASSENGERS = 4;
const MINIMUM_FARE = 5.00;
let total = 0;
// Verificar si es horario nocturno
if (HOUR < 6 || HOUR >= 22) {
// Aplicar recargo nocturno al costo por kilómetro
total =
BASE_FARE +
a * RATE_PER_KILOMETER * NIGHT_SURCHARGE_MULTIPLIER;
} else {
total = BASE_FARE + a * RATE_PER_KILOMETER;
}
// Verificar si hay pasajeros extra y sumar recargo
if (PASSENGERS > INCLUDED_PASSENGERS) {
total +=
(PASSENGERS - INCLUDED_PASSENGERS) *
EXTRA_PASSENGER_CHARGE;
}
// Aplicar tarifa mínima
if (minRate(total, MINIMUM_FARE)) {
total = MINIMUM_FARE;
}
return total;
}
function minRate(total: number, minimumFare: number): boolean {
return total < minimumFare;
}0respuestas