Drill

ProblemsTypeScript › logistics

Which zone price applies

easylogisticsTypeScript

A carrier prices by zone. Look up the per-kilogram rate for a zone; a zone with no entry means it is not served.

zoneRate(zoneRates: map<string, int>, zone: string) → int

Solve it in the editor →

Where you start

function zoneRate(zoneRates: Record<string, number>, zone: string): number {
  
}

Worked examples

CallResult
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;
}

The same problem in another language

More logistics problems in TypeScript