Calculate Reverse Polish Notation
I want to make a Calculator WeixinAPP, but I found that WeixinAPP don't support 'eval' maybe for the security.
In a browser, you can load rpn with a script tag, as you would any other JavaScript library:
<script src="rpn.js" type="text/javascript"></script>
or
<script src="rpn.min.js" type="text/javascript"></script>
isOperator(value)
if value is oneof operators( +-*/()×÷
), return true
isOperator("1"); // return false isOperator("/"); // return true
outputRpn(exp)
return a RPN expression as a array
outputRpn("90+(3-1)*3+10/2"); // return [90,3,1,'-',3,'*','+',10,2,'/','+']
calRpnExp(rpnArr)
return value
var rpn = [90,3,1,'-',3,'*','+',10,2,'/','+']; calRpnExp(rpn) // return 101
calCommonExp(exp)
return value
calCommonExp('90+(3-1)*3+10/2'); // return 101