When the ternary operator fails

you are running into a disallowed parser state (ending an expression with -
this is an opportunity to use ifelse

a = "1+2"
op = ifelse(contains(a, '+'), +, -)
op == +

or, just enclose the operators in parens

a = "1+2"
op = contains(a, '+') ? (+) : (-)
op === +
2 Likes