Drill

ProblemsTypeScript › pricing

Loyalty points for a basket

easypricingTypeScript

The card scheme awards one point for every full ten lira spent, and doubles that on promotion days.

pointsFor(spend: int, doubleDay: bool) → int

Solve it in the editor →

Where you start

function pointsFor(spend: number, doubleDay: boolean): number {
  
}

Worked examples

CallResult
pointsFor(10000, false)10
pointsFor(10999, false)10
pointsFor(10000, true)20
pointsFor(999, false)0

Hint

Integer-divide by 1000, then double if the flag is set.

Reference solution in TypeScript
function pointsFor(spend: number, doubleDay: boolean): number {
  if (spend <= 0) return 0;
  const base = Math.floor(spend / 1000);
  return doubleDay ? base * 2 : base;
}

The same problem in another language

More pricing problems in TypeScript