js easy
Intuition\n Describe your first thoughts on how to solve this problem. \nThe goal is to implement a fluent interface for a calculator. By chaining methods (add,
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe goal is to implement a fluent interface for a calculator. By chaining methods (add, subtract, multiply, etc.), users can perform multiple operations in sequence on the result without needing intermediate variables or steps.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nConstructor: Initialize the Calculator with a starting value.\nMethods: Implement methods (add, subtract, etc.) that modify the result property and return the current instance (this) to enable chaining.\nValidation: Include error handling for invalid operations, such as division by zero.\nResult Retrieval: Provide a getResult method to access the current computed value.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(1)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n\n# Code\n```javascript []\nclass Calculator {\n    \n    /** \n     * @param {number} value\n     */\n    constructor(value) {\n        this.result = value;\n        \n    }\n    \n    /** \n     * @param {number} value\n     * @return {Calculator}\n     */\n    add(value){\n        this.result += value;\n        return this;\n        \n    }\n    \n    /** \n     * @param {number} value\n     * @return {Calculator}\n     */\n    subtract(value){\n        this.result -= value;\n        return this;\n        \n    }\n    \n    /** \n     * @param {number} value\n     * @return {Calculator}\n     */  \n    multiply(value) {\n        this.result *= value;\n        return this;\n        \n\n    }\n    \n    /** \n     * @param {number} value\n     * @return {Calculator}\n     */\n    divide(value) {\n        if(value === 0){\n            throw new Error(\'Division by zero is not allowed\');\n        }\n        this.result /= value\n        return this\n        \n    }\n    \n    /** \n     * @param {number} value\n     * @return {Calculator}\n     */\n    power(value) {\n        this.result = Math.pow(this.result, value)\n        return this\n        \n    }\n    \n    /** \n     * @return {number}\n     */\n    getResult() {\n        return this.result;\n        \n    }\n}\n```
['JavaScript']