diff --git a/src/calculator.ts b/src/calculator.ts index 1234567..abcdefg 100644 --- a/src/calculator.ts +++ b/src/calculator.ts @@ -1,6 +1,12 @@ class Calculator { + private history: string[] = []; + add(a: number, b: number): number { - return a + b; + const result = a + b; + this.logOperation(`add(${a}, ${b}) = ${result}`); + return result; } subtract(a: number, b: number): number { @@ -8,10 +14,16 @@ class Calculator { } multiply(a: number, b: number): number { - return a * b; + const result = a * b; + this.logOperation(`multiply(${a}, ${b}) = ${result}`); + return result; } divide(a: number, b: number): number { - return a / b; + if (b === 0) { + throw new Error('Division by zero is not allowed'); + } + return a / b; } + + private logOperation(operation: string): void { + this.history.push(`${new Date().toISOString()}: ${operation}`); + } } export default Calculator; diff --git a/src/utils.ts b/src/utils.ts index 7654321..1234abc 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,11 @@ /** * Format a number as currency */ -export function formatCurrency(amount: number, currency: string = 'USD'): string { +export function formatCurrency( + amount: number, + currency: string = 'USD', + locale: string = 'en-US' +): string { return new Intl.NumberFormat('en-US', { style: 'currency', currency: currency,