refactor(calculate): extract safe percentage rounding logic into a single reusable helper function#6155
Conversation
…gic into a dedicated safe utility
|
Someone is attempting to deploy a commit to the jhasourav07's projects Team on Vercel. A member of the Team first needs to authorize it. |
📦 Next.js Bundle Size Report (Gzipped Sizes)✨ No significant bundle size changes detected. 📊 Summary of Totals
|
Aamod-Dev
left a comment
There was a problem hiding this comment.
Good extraction of redundant logic into a clean helper function. The calculateSafePercentage in lib/calculate.ts helps clean up the complexity around the weekendRatio calculation. Adding test coverage in lib/calculate.test.ts for zero-division guarantees is an excellent practice. Approved!
|
🎉 Congratulations @ChetanSenta! Your PR has been successfully merged. 🚀 Thank you for contributing to CommitPulse. Your work helps us build a better tool for the community.
Keep building! 💻✨ |
Description
Fixes #6148
Pillar
Visual Preview
Zero behavioral or visual outcome changes. All computed statistical outputs remain identical to previous calculations.
What this PR does
Cleans up redundant, duplicated code patterns in
lib/calculate.ts. The codebase contained several identical inline ternary calculations (total === 0 ? 0 : Math.round(...)) designed to preventNaNor zero division errors when computing ratios likeweekendRatio.This refactor bundles this pattern into a robust
calculateSafePercentage()utility function, improving codebase maintainability and readability.Changes
lib/calculate.tscalculateSafePercentage()helper and replaced redundant inline ternaries.lib/calculate.test.tsChecklist before requesting a review:
CONTRIBUTING.mdfile.npm run formatandnpm run lintlocally and resolved all errors.