这些公式可以通过javascript轻松解决吗?

时间:2018-02-19 10:50:37

标签: javascript

147 p? 53 + x * 36 = 7416

15 - 12? x * 2 = 32

?可以是+,*或 -

我需要同时获得x的值和?

这是微不足道的还是复杂的?我已经在努力将* + - 变成运营商,我不认为eval会帮助我到这里很远,是吗?

1 个答案:

答案 0 :(得分:1)

math.js库有math.eval函数。查看this linkthis link

// provide a scope
var scope = {
   a: 3,
   b: 4
};
math.eval('a * b', scope);              // 12
math.eval('c = 2.3 + 4.5', scope);      // 6.8
scope.c;                                // 6.8