Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis+ 1
JS ŠæŃŠµŠ¾Š±ŃŠ°Š·Š¾Š²Š°Š½ŠøŠµ Š¼Š°Ń Š¾ŠæŠµŃŠ°ŃŠøŠ¹
ŠŠøŃŃ ŠæŃŠ¾ŃŃŠ¾Š¹ ŃŃŠ°Š½ŃŠ»ŃŃŠ¾Ń ,ŠŗŠ°Šŗ ŠæŃŠµŠ¾Š±ŃŠ°Š·Š¾Š²Š°ŃŃ ŃŠøŠ¼Š²Š¾Š»Ń Š¼Š°Ń Š¾ŠæŠµŃŠ°ŃŠøŠ¹ ŠøŠ· String. ŠŃŠøŠ¼ŠµŃ "+" Š° Š“Š¾Š»Š¶Š½Š¾ ŠæŠ¾Š»ŃŃŠøŃŃŃ ŠæŃŠ¾ŃŃŠ¾ +. Š”ŠæŠ°ŃŠøŠ±Š¾ Š±Š¾Š»ŃŃŠ¾Šµ.
3 Respostas
+ 2
ŠŠ°Š½ŠøŠøŠ» ŠŠ»ŠøŠ½ wrote, "I want don't uses this construction ,you can see bellow a part of code.
I have "+" and it should be +(without "if* and etc.).
Thanks.
switch(output[i]){
case "+":st.push(num2 + num1);
break;
case "-":st.push(num2 - num1);
break;
case "/":st.push(num2 / num1);
break;
case "*":st.push(num2 * num1);
break;
}"
Response:
Are you trying to make the evaluator from scratch?
If you don't like JavaScript's standard eval function because of its security issues, you could still use math.js's evaluate function here:
https://mathjs.org/docs/expressions/parsing.html
If you may be interested in math.js's evaluate method, also check my math expression evaluator here which depends on math.js:
https://code.sololearn.com/Wa14229a21a1
If you want to make your own from scratch and support multiple operators like +, -, /, *, also consider order of operation rules like b.e.d.m.a.s. Making your own expression evaluator can quickly get almost as tricky as writing your own programming language if you want to support a lot of operators, brackets...
+ 1
What is your question?
I get the English as:
"I am writing a simple translator how to convert symbols of mat operations from String.
Example "+" and it should be just +.
Thank you so much."
I get that you're doing something but it doesn't say you're stuck on anything or want help. Did you run into a problem? Did you get stuck on something?
If you just want to evaluate expressions like "3 + 4", you could use JavaScript's eval function.
eval("3 + 4") returns 7.
eval("3 * 4") returns 12 so eval isn't restricted to + but I'm not sure if that's a problem to you.
0
I want don't uses this construction ,you can see bellow a part of code.
I have "+" and it should be +(without "if* and etc.).
Thanks.
switch(output[i]){
case "+":st.push(num2 + num1);
break;
case "-":st.push(num2 - num1);
break;
case "/":st.push(num2 / num1);
break;
case "*":st.push(num2 * num1);
break;
}