Solución

@aventuradev·2/6/2026TypeScript
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
Respuestas

Aún no hay respuestas

¡Sé el primero en responder!

Escribir un comentario

Recuerda ser amable. Estás comentando la solución de otra persona. Comparte tu perspectiva de forma constructiva y respetuosa.

Debes iniciar sesión para publicar un comentario.