Solución

@abrahamjlr·19/4/2026TypeScript
solution.tsTypeScript
from typing import Dict

MIN_ORDER_AMOUNT: int = 10
HIGH_SPENDING_THRESHOLD: int = 100

DISCOUNT_RATES: Dict = {
    "gold" : { "high": 0.20, "low": 0.10},
    "silver" : { "high": 0.10, "low": 0.05}
}

def get_subtotal(items: list[dict]) -> float:
    return sum(item["price"] * item["quantity"] for item in items)

def calculate_order_discount(items: list, membership: str) -> float:
    subtotal: float = get_subtotal(items)

    if subtotal < MIN_ORDER_AMOUNT:
        return -1.0

    rates: Dict = DISCOUNT_RATES.get(membership.lower())

    if not rates:
        return float(subtotal)

    discount_percentage = (
        rates["high"] if subtotal >= HIGH_SPENDING_THRESHOLD else rates["low"]
    )

    result: float = subtotal * (1 - discount_percentage)

    return result

exports = calculate_order_discount
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.