Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

减法为啥不能算?subtraction can not be calculated... #1

Closed
jarain opened this issue Jan 9, 2018 · 2 comments
Closed

减法为啥不能算?subtraction can not be calculated... #1

jarain opened this issue Jan 9, 2018 · 2 comments

Comments

@jarain
Copy link

jarain commented Jan 9, 2018

console.log(rpn.calculate('5-2'));

Uncaught TypeError: calcStack.pop(...).toFixed is not a function
at Object.rpnCalculate (rpn.js:149:37)
at Object.calculate (rpn.js:158:24)
....

@Tairraos
Copy link
Owner

Sorry, 正则表达式多打了个符号√。现在好了。请更新最新版本,删除了一个√符号。一直没有关注到有个open issue,今天才看到。。。。不好意思

@Tairraos
Copy link
Owner

Tairraos commented May 28, 2018

如果算式,减号后面有空格,是不会遇到这个问题的。现在已经修正。
原因是因为-2有时候要理解成 “负2”, 有时候要理解成“减2”,如果减号前面是个数字,百分号和阶乘号,那说明它是个“减” 如果减号前面是其它运算符号,那它就是“负” 。
其它符号没有这个转换问题,Unit test里没有使用减法。。。所以。。。。
现在增加了三行减法UT

        expect(rpn.rpnCalculate(rpn.infix2rpn('5-1'))).equal(4);
        expect(rpn.rpnCalculate(rpn.infix2rpn('5+ -2'))).equal(3);
        expect(rpn.rpnCalculate(rpn.infix2rpn('5--2'))).equal(7);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants