Deviopath › TypeScript

Order Total from a Price List

Easy · Null Safety

Prices are stored in a Record<string, number> (an object with string keys and number values).

Write orderTotal(prices: Record<string, number>, items: string[]): number that adds up the price of every item. Looking up a missing key gives undefined, so treat unknown items as costing 0 (the ?? operator helps).

Next: Narrowing with Array.isArray