Drill

ProblemsTypeScript › billing

Early payment discount

mediumbillingTypeScript

A vendor rewards early payment: the further ahead the payment, the larger the discount off the subtotal.

earlyDiscount(subtotal: int, daysEarly: int) → int

Solve it in the editor →

Where you start

function earlyDiscount(subtotal: number, daysEarly: number): number {
  
}

Worked examples

CallResult
earlyDiscount(10000, 10)200
earlyDiscount(5000, 5)50
earlyDiscount(7500, 15)150
earlyDiscount(999, 3)0

Hint

Check the thresholds from largest to smallest.

Reference solution in TypeScript
function earlyDiscount(subtotal: number, daysEarly: number): number {
  if (daysEarly >= 10) return Math.floor(subtotal * 2 / 100);
  if (daysEarly >= 5) return Math.floor(subtotal / 100);
  return 0;
}

The same problem in another language

More billing problems in TypeScript