/**
* Strategy — the part of an algorithm that varies, handed in rather than
* branched on.
*/
type Pricing = (weightKg: number) => number;
const standard: Pricing = (kg) => 4 + kg * 1.1;
const express: Pricing = (kg) => 9 + kg * 2.4;
const courtesy: Pricing = () => 0;
// The quote knows nothing about how a price is arrived at. Adding a fourth
// way to charge does not touch this function.
function quote(weightKg: number, pricing: Pricing): string {
return pricing(weightKg).toFixed(2);
}
const offers: [string, Pricing][] = [
["standard", standard],
["express", express],
["courtesy", courtesy],