(spend: number, credits: number)
| 1 | export function calculateSpendingsWithCredits(spend: number, credits: number) { |
| 2 | const totalSpent = calculateTotalSpent(spend, credits); |
| 3 | const creditsUsed = calculateCreditsUsed(spend, credits); |
| 4 | const remainingCredits = calculateRemainingCredits(spend, credits); |
| 5 | |
| 6 | return { totalSpent, creditsUsed, remainingCredits }; |
| 7 | |
| 8 | function calculateTotalSpent(spend: number, credits: number) { |
| 9 | const totalSpent = spend - credits; |
| 10 | |
| 11 | return totalSpent > 0 ? totalSpent : 0; |
| 12 | } |
| 13 | |
| 14 | function calculateCreditsUsed(spend: number, credits: number) { |
| 15 | return spend - credits < 0 ? spend : credits; |
| 16 | } |
| 17 | |
| 18 | function calculateRemainingCredits(spend: number, credits: number) { |
| 19 | const remainingCredits = credits - spend; |
| 20 | |
| 21 | return remainingCredits > 0 ? remainingCredits : 0; |
| 22 | } |
| 23 | } |
no test coverage detected