OneCompiler

Postfix_Evaluation_in_JavaScript

142
 str  = ["10", "6", "9", "3", "+", "-11", "*", "/", "*", "17", "+", "5", "+"];

stack = [];

for(i=0; i<str.length; i++){
  
  if(str[i]=="+" || str[i]=="-" || str[i]=="/" || str[i]=="*"){
    n = parseInt(stack.pop());
    m = parseInt(stack.pop());
    
    switch(str[i]){
      case "+":
        stack.push(parseInt(m+n));
        break;
        
      case "-":
        stack.push(parseInt(m-n));
        break;
        
      case "*":
        stack.push(parseInt(m*n));
        break;
        
      case "/":
        stack.push(parseInt(m/n));
        break;
        
    }
    
  }
  else{
    stack.push(str[i]);
  }
  
}

console.log(stack[0]);