remove comments
This commit is contained in:
parent
74dd75a159
commit
96780f5abf
1 changed files with 1 additions and 36 deletions
|
|
@ -1,50 +1,23 @@
|
|||
/**
|
||||
* Calculator class for performing basic arithmetic operations
|
||||
* Uses method chaining to allow consecutive operations
|
||||
*/
|
||||
class Calculator {
|
||||
/**
|
||||
* Initialize calculator with result set to 0
|
||||
*/
|
||||
constructor() {
|
||||
this.result = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a number to the current result
|
||||
* @param {number} number - The number to add
|
||||
* @returns {Calculator} - Returns this instance for method chaining
|
||||
*/
|
||||
add(number) {
|
||||
this.result += number;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract a number from the current result
|
||||
* @param {number} number - The number to subtract
|
||||
* @returns {Calculator} - Returns this instance for method chaining
|
||||
*/
|
||||
subtract(number) {
|
||||
this.result -= number;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply the current result by a number
|
||||
* @param {number} number - The number to multiply by
|
||||
* @returns {Calculator} - Returns this instance for method chaining
|
||||
*/
|
||||
multiply(number) {
|
||||
this.result *= number;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide the current result by a number
|
||||
* @param {number} number - The number to divide by
|
||||
* @returns {Calculator} - Returns this instance for method chaining
|
||||
* @throws {Error} - Throws error if attempting to divide by zero
|
||||
*/
|
||||
divide(number) {
|
||||
if (number === 0) {
|
||||
throw new Error("Cannot divide by zero");
|
||||
|
|
@ -53,18 +26,10 @@ class Calculator {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current result value
|
||||
* @returns {number} - The current result
|
||||
*/
|
||||
getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the result to 0
|
||||
* @returns {Calculator} - Returns this instance for method chaining
|
||||
*/
|
||||
reset() {
|
||||
this.result = 0;
|
||||
return this;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue