Add comparison operators < and > to calculateRPN function
This commit is contained in:
@@ -9,6 +9,8 @@ function toRPN(expression:string) {
|
||||
'/': {precedence: 3, associativity: 'Left'},
|
||||
'^': {precedence: 4, associativity: 'Left'},
|
||||
'%': {precedence: 3, associativity: 'Left'},
|
||||
'<': {precedence: 1, associativity: 'Left'},
|
||||
'>': {precedence: 1, associativity: 'Left'},
|
||||
};
|
||||
|
||||
expression = expression.replace(/\s+/g, '');
|
||||
@@ -52,6 +54,8 @@ function calculateRPN(expression:string) {
|
||||
case '/': stack.push(a / b); break;
|
||||
case '^': stack.push(a ** b); break;
|
||||
case '%': stack.push(a % b); break;
|
||||
case '<': stack.push(a < b ? 1 : 0); break;
|
||||
case '>': stack.push(a > b ? 1 : 0); break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user