Problems › TypeScript › logistics
Which zone price applies
A carrier prices by zone. Look up the per-kilogram rate for a zone; a zone with no entry means it is not served.
- Rates are per kilogram, in minor units.
- A zone that is not in the table is unsupported: return 0.
zoneRate(zoneRates: map<string, int>, zone: string) → int
Where you start
function zoneRate(zoneRates: Record<string, number>, zone: string): number {
}
Worked examples
| Call | Result |
|---|---|
zoneRate({"a":120,"b":180,"c":250}, "a") | 120 |
zoneRate({"a":120,"b":180}, "c") | 0 |
zoneRate({}, "a") | 0 |
zoneRate({"x":0}, "x") | 0 |
Hint
Map lookup, then a default.
Reference solution in TypeScript
function zoneRate(zoneRates: Record<string, number>, zone: string): number {
return zoneRates[zone] ?? 0;
}