I tried to write a computation mathematical expression and store each sign into an array.
For example, I want to convert the array:
let arr = ['10', '-', '(', '2', '+', '1', ')', '*', '3'];
To the following expression:
let result = 10 - (2 + 1) * 3; // 1
Any suggestions on how to achieve this?
eval(arr.join(' '))pushandpop). Pretty much you keep pushing numbers to one array and operators to the other array. When you find something that has higher precedence, you handle it in place. You do this until the arrays are empty.