const antiEval = (str) => {
let arr = str.split(' ');
switch (arr[1]) {
case '+':
return Math.round((+arr[0] + +arr[2]) * 100) / 100;
break;
case '-':
return Math.round((+arr[0] - +arr[2]) * 100) / 100;
break;
case '/':
return Math.round((+arr[0] / +arr[2]) * 100) / 100;
break;
case '*':
return Math.round((+arr[0] * +arr[2]) * 100) / 100;
break;
};
};
var value = '(5+7)*10'.match(/(^[0-9*\/\\(\\)+-]+$)/);
var res = new Function('return '+ value );
console.log(res()); // => 120
илиclass Calc{
public float Result;
public Calc Add(float a){
Result += a;
return this;
}
public float GetResult() {
return Result;
}
}
var a = new Calc().Add(2).Add(5).Minus(4).GetResult();