MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / prefixevaluator

Function prefixevaluator

assets/js/prefixevaluator.js:5–39  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3var evalstack=[];
4
5function prefixevaluator()
6{
7 evalst= document.getElementById("prefixvalue").value;
8 eval=evalst.split(" ");
9 for(var i=eval.length-1;i>=0;i--)
10 {
11 if(!operator(eval[i]))
12 {
13 push(eval[i]);
14 }
15 else
16 {
17 var op1=parseInt(pop());
18 var op2=parseInt(pop());
19
20 if(eval[i]=="+")
21 {
22 push(op1+op2);
23 }
24 else if(eval[i]=="-")
25 {
26 push(op1-op2);
27 }
28 else if(eval[i]=="*")
29 {
30 push(op1*op2);
31 }
32 else
33 {
34 push(op1/op2);
35 }
36 }
37 }
38 document.getElementById("text").innerHTML=(pop());
39}
40
41function push(e)
42{

Callers

nothing calls this directly

Calls 3

operatorFunction · 0.70
pushFunction · 0.70
popFunction · 0.70

Tested by

no test coverage detected