What does this policy-based calculation print for a VIP order and a regular order?

from SOLID principles
TypeScript 6 beginner 2 min

What does this policy-based calculation print for a VIP order and a regular order?

JavaScript
class LoyaltyDiscount {
  discountFor(order) {
    return order.customerKind === 'vip' ? order.subtotal * 0.1 : 0;
  }
}

const policy = new LoyaltyDiscount();
const totals = [
  { subtotal: 100, customerKind: 'vip' },
  { subtotal: 100, customerKind: 'regular' },
].map((order) => order.subtotal - policy.discountFor(order));

console.log(totals.join(', '));
Open in playground
Report an error