@@ -11,7 +11,7 @@ function remove_duplicate_negatives(tree) {
11
11
var operator = tree [ 0 ] ;
12
12
var operands = tree . slice ( 1 ) ;
13
13
14
- if ( operator === '-' && operands [ 0 ] [ 0 ] === '-' ) {
14
+ if ( operator === '-' && Array . isArray ( operands [ 0 ] ) && operands [ 0 ] [ 0 ] === '-' ) {
15
15
return remove_duplicate_negatives ( operands [ 0 ] [ 1 ] ) ;
16
16
}
17
17
@@ -43,7 +43,7 @@ function normalize_negatives_in_factors(tree) {
43
43
var operands_no_negatives = [ ] ;
44
44
45
45
for ( var i = 0 ; i < operands . length ; i ++ ) {
46
- if ( operands [ i ] [ 0 ] === '-' ) {
46
+ if ( Array . isArray ( operands [ i ] ) && operands [ i ] [ 0 ] === '-' ) {
47
47
sign *= - 1 ;
48
48
operands_no_negatives . push ( operands [ i ] [ 1 ] ) ;
49
49
}
@@ -78,6 +78,9 @@ function sort_key(tree, params = {}) {
78
78
}
79
79
if ( typeof tree === 'string' ) {
80
80
// if string is a constant, return number with value?
81
+ if ( tree === "-" || tree === "+" ) {
82
+ return [ 8 , 'plus_minus_string' , tree ]
83
+ }
81
84
return [ 1 , 'symbol' , tree ] ;
82
85
}
83
86
if ( typeof tree === 'boolean' ) {
@@ -227,7 +230,7 @@ function coeff_factors_from_term(term, string_factors) {
227
230
}
228
231
f [ ind ] ++ ;
229
232
continue ;
230
- } else if ( Array . isArray ( factor ) && factor [ 0 ] === "^" || factor [ 0 ] === '-' ) {
233
+ } else if ( Array . isArray ( factor ) && ( factor [ 0 ] === "^" || factor [ 0 ] === '-' ) ) {
231
234
let result = coeff_factors_from_term ( factor , string_factors ) ;
232
235
for ( let ind in result . factor_contains ) {
233
236
if ( f [ ind ] === undefined ) {
0 commit comments