Why this matters
Reduces duplicate work and logic drift.
Compute expensive derived values once per input set and reuse them rather than recalculating in multiple places.
Reduces duplicate work and logic drift.
Side-by-side examples engineers can pattern-match during review.
const a = items.reduce(...);
const b = items.reduce(...); // same logicconst lineTotal=i=>i.price*i.qty; const total=items.reduce((acc,i)=>acc+lineTotal(i),0);recompute the same reduce several timesderive once and reuseFrom the same buckets as this rule.