Elffuss BraidHub

kikocis/continue public

main · 1.7 KiBRawPermalink
1class Calculator {
2 constructor() {
3 this.result = 0;
4 }
5
6 add(number) {
7 this.result += number;
8 return this;
9 }
10
11 subtract(number) {
12 this.result -= number;
13 return this;
14 }
15
16 multiply(number) {
17 this.result *= number;
18 return this;
19 }
20
21 divide(number) {
22 if (number === 0) {
23 throw new Error("Cannot divide by zero");
24 }
25 this.result /= number;
26 return this;
27 }
28
29 getResult() {
30 return this.result;
31 }
32
33 reset() {
34 this.result = 0;
35 return this;
36 }
37}
38
39---
40
41// ... existing code ...
42
43 /**
44 * Divides the current result by the given number
45 * @param {number} number - The number to divide by
46 * @throws {Error} If attempting to divide by zero
47 * @returns {Calculator} The calculator instance for chaining
48 */
49 divide(number) {
50 if (number === 0) {
51 throw new Error("Cannot divide by zero");
52 }
53 this.result /= number;
54 return this;
55 }
56
57// ... existing code ...
58
59---
60
61class Calculator {
62 constructor() {
63 this.result = 0;
64 }
65
66 add(number) {
67 this.result += number;
68 return this;
69 }
70
71 subtract(number) {
72 this.result -= number;
73 return this;
74 }
75
76 multiply(number) {
77 this.result *= number;
78 return this;
79 }
80
81+ /**
82+ * Divides the current result by the given number
83+ * @param {number} number - The number to divide by
84+ * @throws {Error} If attempting to divide by zero
85+ * @returns {Calculator} The calculator instance for chaining
86+ */
87 divide(number) {
88 if (number === 0) {
89 throw new Error("Cannot divide by zero");
90 }
91 this.result /= number;
92 return this;
93 }
94
95 getResult() {
96 return this.result;
97 }
98
99 reset() {
100 this.result = 0;
101 return this;
102 }
103}