Add support for bitwise OR and AND operators in calculateRPN function

This commit is contained in:
kwaroran
2024-04-25 04:10:00 +09:00
parent 45a9068e58
commit 6ae39619b7

View File

@@ -12,6 +12,8 @@ function toRPN(expression:string) {
'%': {precedence: 3, associativity: 'Left'},
'<': {precedence: 1, associativity: 'Left'},
'>': {precedence: 1, associativity: 'Left'},
'|': {precedence: 0, associativity: 'Left'},
'&': {precedence: 0, associativity: 'Left'},
};
expression = expression.replace(/\s+/g, '');
@@ -57,6 +59,8 @@ function calculateRPN(expression:string) {
case '%': stack.push(a % b); break;
case '<': stack.push(a < b ? 1 : 0); break;
case '>': stack.push(a > b ? 1 : 0); break;
case '|': stack.push(a || b); break;
case '&': stack.push(a && b); break;
}
}
});