Fast solution ✅🚀
IntuitionThe goal is to implement a chainable calculator that performs basic arithmetic operations (add, subtract, multiply, divide) and an advanced operation (
# Intuition
The goal is to implement a chainable calculator that performs basic arithmetic operations (`add`, `subtract`, `multiply`, `divide`) and an advanced operation (`power`). The chaining feature allows multiple operations to be performed in a single statement. For example:


```
const calc = new Calculator(10);
calc.add(5).multiply(2).subtract(3).getResult(); 
```


This requires each method to return the instance of the `Calculator` class (`this`), enabling the chaining behavior.
# Approach
1. **Initialization**:
    - The constructor initializes the `result` property with the given value.
2. **Arithmetic Operations**:
    - Each method (`add`, `subtract`, `multiply`, `divide`, `power`) updates the `result` property based on the input value and returns `this` to allow method chaining.
3. **Division by Zero**:
    - To handle invalid operations, the `divide` method checks if the divisor is `0` and throws an error if so.
4. **Retrieving the Result**:
    - The `getResult` method simply returns the current value of the `result` property.
# Complexity
- Time complexity:
    - Each operation (add, subtract, multiply, devide, power) runs in O(1), as it performs a single arithmetic operation.
- Space complexity:
O(1), since no additional data structures are used
# Code
```javascript []
class Calculator {
    
    /** 
     * @param {number} value
     */
    constructor(value) {
          this.result = value;
    }
    
    /** 
     * @param {number} value
     * @return {Calculator}
     */
    add(value){
         this.result += value;
    return this;
    }
    
    /** 
     * @param {number} value
     * @return {Calculator}
     */
    subtract(value){
          this.result -= value;
    return this;
    }
    
    /** 
     * @param {number} value
     * @return {Calculator}
     */  
    multiply(value) {
        this.result *= value;
    return this;
    }
    
    /** 
     * @param {number} value
     * @return {Calculator}
     */
    divide(value) {
          if (value === 0) {
      throw new Error("Division by zero is not allowed");
    }
    this.result /= value;
    return this;
    }
    
    /** 
     * @param {number} value
     * @return {Calculator}
     */
    power(value) {
        this.result **= value;
    return this;
    }
    
    /** 
     * @return {number}
     */
    getResult() {
         return this.result;
    }
}
```

![upvote pls.png](https://assets.leetcode.com/users/images/d3cfa5c0-7ffb-4956-9502-fefcd654f538_1737432353.4995253.png)

['JavaScript']