Elffuss BraidHub

kikocis/continue public

main · 670 BRawPermalink
1class Calculator {
2 private result: number;
3
4 constructor() {
5 this.result = 0;
6 }
7
8 add(number: number): Calculator {
9 this.result += number;
10 return this;
11 }
12
13 subtract(number: number): Calculator {
14 this.result -= number;
15 return this;
16 }
17
18 multiply(number: number): Calculator {
19 this.result *= number;
20 return this;
21 }
22
23 divide(number: number): Calculator {
24 if (number === 0) {
25 throw new Error("Cannot divide by zero");
26 }
27 this.result /= number;
28 return this;
29 }
30
31 getResult(): number {
32 return this.result;
33 }
34
35 reset(): Calculator {
36 this.result = 0;
37 return this;
38 }
39}
40
41export default Calculator;