Skip to content

emaiqi/rpn.js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

rpn.js

Calculate Reverse Polish Notation

Why I do it

I want to make a Calculator WeixinAPP, but I found that WeixinAPP don't support 'eval' maybe for the security.

Getting it

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>

Usage

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

About

Calculate Reverse Polish Notation

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%