Drill

ProblemsJavaScript › billing

Look up the tax rate for a region

easybillingJavaScript

A billing system stores tax rates by region code. Look up the rate; an unknown region is not taxed.

regionTax(regionRates: map<string, int>, region: string) → int

Solve it in the editor →

Where you start

function regionTax(regionRates, region) {
  
}

Worked examples

CallResult
regionTax({"US":700,"EU":1900,"TR":1800}, "EU")1900
regionTax({"US":700}, "UK")0
regionTax({}, "US")0
regionTax({"DE":1900,"FR":2000}, "DE")1900

Hint

Map lookup with a default.

Reference solution in JavaScript
function regionTax(regionRates, region) {
  return regionRates[region] ?? 0;
}

The same problem in another language

More billing problems in JavaScript