Solución

@bryancastro·6/7/2026TypeScript
solution.tsTypeScript
const RATE_PER_KM = 1.20
const HOUR_INIT_NIGHT = 6
const HOUR_END_NIGHT = 22
const BASE_PRICE = 2.50
const MIN_PRICE = 5.00
const PRICE_NIGHT = 1.5
const EXTRA_BY_PASSENGERS = 0.30
const MAX_PASSENGERS = 4

const isNightSchedule = (hour: number) => hour < HOUR_INIT_NIGHT || hour >= HOUR_END_NIGHT

function calculateCost(hour: number, passengers: number) {
  // Verificar si es horario nocturno
  if (isNightSchedule(hour)) {
    // Aplicar recargo nocturno al costo por kilómetro
    return BASE_PRICE + passengers * RATE_PER_KM * PRICE_NIGHT;
  }

  return BASE_PRICE + passengers * RATE_PER_KM;
}

export function calculateTaxiFare(a: number, b: number, c: number): number {
  let total = 0;
  total = calculateCost(b, a)

  // Verificar si hay pasajeros extra y sumar recargo
  if (c > MAX_PASSENGERS) {
    total = total + (c - MAX_PASSENGERS) * EXTRA_BY_PASSENGERS;
  }

  // Aplicar tarifa mínima
  if (total < MIN_PRICE) {
    total = MIN_PRICE;
  }

  return total;
}
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.