Solución

JL@juanluisabreu_4c541ef6
·2/4/2026TypeScript
solution.tsTypeScript
// Precios base por tipo de habitación
const STANDARD_RATE = 80;
const DELUXE_RATE = 150;
const SUITE_RATE = 250;

// Recargo por fin de semana
const WEEKEND_SURCHARGE = 0.20;

// Descuentos por nivel de lealtad
const SILVER_DISCOUNT = 0.05;
const GOLD_DISCOUNT = 0.10;
const PLATINUM_DISCOUNT = 0.15;

// Noches mínimas requeridas
const MIN_NIGHTS = 1;

// Retorna el precio base según el tipo de habitación
function getBaseRate(roomType: string): number {
  // Seleccionar tarifa según tipo de habitación
  if (roomType === "standard") return STANDARD_RATE;
  if (roomType === "deluxe") return DELUXE_RATE;
  if (roomType === "suite") return SUITE_RATE;
  return 0;
}

// Retorna el porcentaje de descuento según el nivel de lealtad
function getLoyaltyDiscount(loyaltyLevel: string): number {
  // Seleccionar descuento según nivel de membresía
  if (loyaltyLevel === "silver") return SILVER_DISCOUNT;
  if (loyaltyLevel === "gold") return GOLD_DISCOUNT;
  if (loyaltyLevel === "platinum") return PLATINUM_DISCOUNT;
  return 0;
}

export function calculateHotelStayCost(nights: number, roomType: string, isWeekend: boolean, loyaltyLevel: string): number {
  // Validar que la estadía tenga al menos una noche
  if (nights < MIN_NIGHTS) return -1;

  const baseRate = getBaseRate(roomType);
  const loyaltyDiscount = getLoyaltyDiscount(loyaltyLevel);

  // Aplicar recargo de fin de semana si corresponde
  const weekendMultiplier = isWeekend ? 1 + WEEKEND_SURCHARGE : 1;

  // Calcular costo total aplicando recargo y descuento
  return baseRate * nights * weekendMultiplier * (1 - loyaltyDiscount);
}
0respuestas
Respuestas
0

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.
Markdown