Implement in JavaScript a shipping-cost calculator with three progressively richer pricing models based on a configuration object keyed by destination.
-
Flat per‑unit price: given config[destination] = { unitPrice }, return unitPrice * quantity.
-
Tiered per‑unit pricing: given config[destination] = { tiers: [ { upTo: q1, unitPrice: p1 }, { upTo: q2, unitPrice: p2 }, ..., { upTo: Infinity, unitPrice: pk } ] }, compute the total by applying each tier only to the items that fall within that tier’s range; treat each upTo as inclusive and accumulate across tiers.
-
Flat base for the first n items plus tiers afterward: given config[destination] = { baseFlat: { upTo: n, amount: F }, tiers: [...] }, charge F once for quantities 1..n; for quantities > n, charge F for the first n items and then apply tiered pricing starting from item n+1. Carefully avoid off‑by‑one mistakes at n and other tier boundaries. Define the function signature calculateShipping(destination, quantity, config) and describe tests for edge cases (quantity 0, exactly at cutoffs, unknown location, negative inputs, floating‑point handling).