math-expression-evaluator
math-expression-evaluator copied to clipboard
[Feature request] Support for conditional operator a ? b : c
It would be great to support conditional expressions (like "if statements").
Similar to math.js "Conditional expression" seen here https://mathjs.org/docs/expressions/syntax.html
mathjs has their own parser, AST etc and all while this library is just a modified version of dijkstra's algorithm. > < == etc symbols i can implement but boolean ? number : number. it means if boolean ? X should give X or boolean and X:Y should give Y if X = boolean or X if X != boolean. I will think and try my best about it in coming weekend or so..
No problem - it sounds like a pretty complicated feature (do you allow nested "if" conditionals?).
1 > 2 ? 3 : 2 < 4 ? 5 : 6 => 3
1 < 2 ? 3 : 2 < 4 ? 5 : 6 => 5
It looks like it can get complicated and it's not a rush for me (I figured out a workaround for now). Thank you for responding, regardless.
Hi there, I would like to vote for this feature, if is possible! Thanks for the great work with this :)