// Asked in Publicis sepient, Meesho
// How would you implement a calculator class with methods for addition,
// subtraction, and multiplication, supporting method chaining?
// calculator.add(3).multiply(4).subtract(5).getValue()
// const calculator = new Calculator(2);
// console.log(calculator.add(3).multiply(4).subtract(5).getValue()); //15
constructor(initialValue = 0) {
this.value = initialValue;
return this; // Enable method chaining
return this; // Enable method chaining
return this; // Enable method chaining
// this will return same instance of the Calculator, will allow method chaining
const calculator = new Calculator(2);
console.log(calculator.add(3).multiply(4).subtract(5).getValue());