Create an extendable calculator
importance: 5
 Please note how methods are stored. They are simply added to the internal object.
 All tests and numeric conversions are done in the
calculate
method. In future it may be extended to support more complex expressions.
Create a constructor function Calculator
that creates “extendable” calculator objects.
The task consists of two parts.

First, implement the method
calculate(str)
that takes a string like"1 + 2"
in the format “NUMBER operator NUMBER” (spacedelimited) and returns the result. Should understand plus+
and minus
.Usage example:
let calc = new Calculator; alert( calc.calculate("3 + 7") ); // 10

Then add the method
addMethod(name, func)
that teaches the calculator a new operation. It takes the operatorname
and the twoargument functionfunc(a,b)
that implements it.For instance, let’s add the multiplication
*
, division/
and power**
:let powerCalc = new Calculator; powerCalc.addMethod("*", (a, b) => a * b); powerCalc.addMethod("/", (a, b) => a / b); powerCalc.addMethod("**", (a, b) => a ** b); let result = powerCalc.calculate("2 ** 3"); alert( result ); // 8
 No brackets or complex expressions in this task.
 The numbers and the operator are delimited with exactly one space.
 There may be error handling if you’d like to add it.