for example, if I had a STRING = "3+3*(4-1)" if a ran a function and wanted it to solve the equation using javascript, what Would I start with?
Asked
Active
Viewed 109 times
0
-
https://en.wikipedia.org/wiki/Shunting-yard_algorithm – Aplet123 Dec 10 '20 at 01:53
-
https://stackoverflow.com/questions/2276021/evaluating-a-string-as-a-mathematical-expression-in-javascript – newbieprogrammer Dec 10 '20 at 01:59
-
https://stackoverflow.com/questions/6479236/calculate-string-value-in-javascript-not-using-eval – Trentium Dec 13 '20 at 20:25
1 Answers
1
Assuming the equation has a correct syntax of javascript, you can use eval
to evaluate the value.
i.e.
eval("3+3*(4-1)")
= 12

Lukabot
- 189
- 3
- 11