Solución
JL@juanluisabreu_4c541ef6
·2/4/2026TypeScriptsolution.tsTypeScript
function getNightSurcharge(distancia: number, horario: number) {
let tarifa = 0;
const BASE_FARE = 2.50;
const RATE_PER_KM = 1.20;
const NIGTH_MULTIPLIER = 1.5;
const HORARIO_NOCTURNO_MINIMO = 6;
const HORARIO_NOCTURNO_MAXIMO = 22;
// Verificar si es horario nocturno
if (horario < HORARIO_NOCTURNO_MINIMO || horario >= HORARIO_NOCTURNO_MAXIMO) {
// Aplicar recargo nocturno al costo por kilómetro
tarifa = BASE_FARE + distancia * RATE_PER_KM * NIGTH_MULTIPLIER;
} else {
tarifa = BASE_FARE + distancia * RATE_PER_KM;
}
return tarifa;
}
function getPassengerSurcharge(tarifa: number, pasajeros: number){
const MAX_PASSENGER = 4;
const PASSENGER_MULTIPLIER = 0.30;
// Verificar si hay pasajeros extra y sumar recargo
if (pasajeros > MAX_PASSENGER) {
tarifa = tarifa + (pasajeros - MAX_PASSENGER) * PASSENGER_MULTIPLIER;
}
return tarifa;
}
export function calculateTaxiFare(distancia: number, horario: number, pasajeros: number): number {
const MIN_TARIFA = 5;
let tarifa = 0;
tarifa = getNightSurcharge(distancia, horario);
tarifa = getPassengerSurcharge(tarifa, pasajeros);
// Aplicar tarifa mínima
if (tarifa < MIN_TARIFA) {
tarifa = MIN_TARIFA;
}
return tarifa;
}0respuestas