Drill

ProblemsTypeScript › orders

Does this basket ship free

easyordersTypeScript

The storefront shows a "free shipping" badge, but the rule has an exception for heavy baskets that finance insisted on.

shipsFree(basketTotal: int, grams: int, threshold: int) → bool

Solve it in the editor →

Where you start

function shipsFree(basketTotal: number, grams: number, threshold: number): boolean {
  
}

Worked examples

CallResult
shipsFree(50000, 3000, 30000)true
shipsFree(50000, 25000, 30000)false
shipsFree(30000, 1000, 30000)true
shipsFree(29999, 1000, 30000)false

Hint

The weight rule overrides the value rule, so check it second — or check it first and return early.

Reference solution in TypeScript
function shipsFree(basketTotal: number, grams: number, threshold: number): boolean {
  if (basketTotal <= 0) return false;
  if (grams > 20000) return false;
  return basketTotal >= threshold;
}

The same problem in another language

More orders problems in TypeScript