Arrays often include items with missing numbers. A price may be undefined or null. Sum only the numbers and treat missing as 0.
const prices = [1, undefined, 3, null];
const total = prices.reduce((acc, p) => acc + (p ?? 0), 0);Keep the function pure and return a number result.
Add up prices, skipping missing values.
interface Item { name: string; price?: number | null }.totalPrice(items: Item[]): number.null and undefined prices as 0.0 for an empty list.