Magic numbers make code unreadable. What does 86400000 mean? What about 0.2?
// dirty
function solve(priceInCents: number, ageInMs: number): { discounted: number; ageInDays: number } {
const discounted = priceInCents * (1 - 0.2);
const ageInDays = ageInMs / 86400000;
return { discounted: Math.round(discounted), ageInDays: Math.floor(ageInDays) };
}Refactor by introducing named constants so the intent is self-documenting.
The output must remain identical.
Sample tests