Fix #10, add test
This commit is contained in:
6
dist/index.js
vendored
6
dist/index.js
vendored
@ -219,7 +219,7 @@ var parseExpression = function parseExpression(expression) {
|
||||
stack.push('-' + cur);
|
||||
|
||||
// 2 - 5 is also OK, pass
|
||||
} else if (_.isNumber(beforeSign)) {
|
||||
} else if (_.isNumber(beforeSign) || isVariable(beforeSign)) {
|
||||
stack.push(cur);
|
||||
} else {
|
||||
stack[past] += cur;
|
||||
@ -478,8 +478,10 @@ var fixFloat = function fixFloat(number) {
|
||||
* @return {Boolean}
|
||||
* true if variable, else false
|
||||
*/
|
||||
|
||||
var SPECIALS = '()[]{}'.split('');
|
||||
var isVariable = function isVariable(a) {
|
||||
return typeof a === 'string' && !_.isNumber(a) && !_operators2['default'][a] && a === a.toLowerCase();
|
||||
return typeof a === 'string' && !_.isNumber(a) && !_operators2['default'][a] && a === a.toLowerCase() && SPECIALS.indexOf(a) === -1;
|
||||
};
|
||||
|
||||
exports.isVariable = isVariable;
|
||||
|
3
dist/tests/equation.js
vendored
3
dist/tests/equation.js
vendored
@ -13,6 +13,9 @@ describe('Equations', function () {
|
||||
var equation = _M2['default'].equation('x+2');
|
||||
|
||||
_expect.expect(equation(2)).to.equal(4);
|
||||
|
||||
var subtraction = _M2['default'].equation('x - 3');
|
||||
_expect.expect(subtraction(10)).to.equal(7);
|
||||
});
|
||||
|
||||
it('should work with multiple variables', function () {
|
||||
|
Reference in New Issue
Block a user