4 ms·
I would show examples in README on use of it along with string interpolation, as it's not too useful with only constants. Eg. const a = 3; const b = 2;
by fuzzythinker 4y ago
I would show examples in README on use of it along with string interpolation, as it's not too useful with only constants.
Eg.
const a = 3;
const b = 2;
const expression = new Expression(`${a}*${b}(6/3(5--2))`);
const result = expression.evaluate();
document.getElementById("app").innerHTML = `a*b( 6 / 3( 5 - - 2 ) )= ${result}`;
Edit: formating
- olamide203 4y agoNice tip, i'm planning to add an identifier node class so that you can pass a scope with the values to be used during evaluation. Eg. const a = 2; const b = 6; const c = 3 const expression = new Expression('a \ b * c') const result = expression.scope({a, b, c}).evaluate(); document.getElementById("app").innerHTML `${a} \ ${b} * ${c}= ${result}`
- gus_massa 4y ago[Add an empty line and then two spaces before each line to trigger the "code" mode.]
- fuzzythinker 4y agoVery welcome solution. String interpolation makes it possible, but it's bad DX.
- olamide203 4y agoyeah having to type ${} everywhere makes the code a little bit messy.