JSFiddle - React, Tailwind, and code Playground
JavaScript
function m(x,l,o,r){
L=(f=parseFloat)(l);
R=f(r);
return o=='*'?L*R:o=='/'?L/R:o=='+'?L+R:L-R;
};
M=/(\-?\d+\.?\d*)([\*\/\+\-])(\-?\d+\.?\d*)/;
for(s=prompt("Enter some math:", "-2 + 6 / 2 * 8 - 1 / 2.5 - 18").replace(/ /g, "");M.test(s);s=s.replace(M,m)){};
alert(s)