JS ŠæрŠµŠ¾Š±Ń€Š°Š·Š¾Š²Š°Š½ŠøŠµ Š¼Š°Ń‚ Š¾ŠæŠµŃ€Š°Ń†ŠøŠ¹ | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

JS ŠæрŠµŠ¾Š±Ń€Š°Š·Š¾Š²Š°Š½ŠøŠµ Š¼Š°Ń‚ Š¾ŠæŠµŃ€Š°Ń†ŠøŠ¹

ŠŸŠøшу ŠæрŠ¾ŃŃ‚Š¾Š¹ трŠ°Š½ŃŠ»ŃŃ‚Š¾Ń€ ,ŠŗŠ°Šŗ ŠæрŠµŠ¾Š±Ń€Š°Š·Š¾Š²Š°Ń‚ŃŒ сŠøŠ¼Š²Š¾Š»Ń‹ Š¼Š°Ń‚ Š¾ŠæŠµŃ€Š°Ń†ŠøŠ¹ ŠøŠ· String. ŠŸŃ€ŠøŠ¼ŠµŃ€ "+" Š° Š“Š¾Š»Š¶Š½Š¾ ŠæŠ¾Š»ŃƒŃ‡Šøтся ŠæрŠ¾ŃŃ‚Š¾ +. Š”ŠæŠ°ŃŠøŠ±Š¾ Š±Š¾Š»ŃŒŃˆŠ¾Šµ.

11th Apr 2021, 3:19 AM
Š”Š°Š½ŠøŠøŠ» Š•Š»ŠøŠ½
Š”Š°Š½ŠøŠøŠ» Š•Š»ŠøŠ½ - avatar
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...
11th Apr 2021, 2:42 PM
Josh Greig
Josh Greig - avatar
+ 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.
11th Apr 2021, 6:13 AM
Josh Greig
Josh Greig - avatar
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; }
11th Apr 2021, 6:34 AM
Š”Š°Š½ŠøŠøŠ» Š•Š»ŠøŠ½
Š”Š°Š½ŠøŠøŠ» Š•Š»ŠøŠ½ - avatar