Skip to content

Commit

Permalink
fix(WebsiteCredibility): improve trend calculation readability
Browse files Browse the repository at this point in the history
- Refactor conditional return for better clarity
- Enhance code structure for maintainability

(your code's readability is like a secret menu, good luck figuring it out)
  • Loading branch information
shanegrouber committed Jan 8, 2025
1 parent 1103f0d commit 4146dcf
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,14 @@ export const WebsiteCredibility: FunctionComponent<{
);

const calculateTrend = (data: Array<{ label: string; value: string }>) => {
if (data.length < 2) return { direction: 'No trend data', percentage: 0 };
if (data.length < 2) {
return { direction: 'No trend data', percentage: 0 };
}
const lastMonthValue = parseInt(data[data.length - 1]?.value ?? '0');
const previousMonthValue = parseInt(data[data.length - 2]?.value ?? '0');
const percentageChange = ((lastMonthValue - previousMonthValue) / previousMonthValue) * 100;
const direction = lastMonthValue > previousMonthValue ? 'up' : 'down';

return { direction, percentage: Math.abs(percentageChange) };
};

Expand Down

0 comments on commit 4146dcf

Please sign in to comment.