feat: Add support for logical NOT operator in toRPN function

This commit is contained in:
kwaroran
2024-05-07 04:29:16 +09:00
parent 50fd644539
commit b8abb977a2

View File

@@ -16,7 +16,8 @@ function toRPN(expression:string) {
'&': {precedence: 1, associativity: 'Left'},
'≤': {precedence: 1, associativity: 'Left'},
'≥': {precedence: 1, associativity: 'Left'},
'=': {precedence: 1, associativity: 'Left'}
'=': {precedence: 1, associativity: 'Left'},
'!': {precedence: 5, associativity: 'Right'},
};
const operatorsKeys = Object.keys(operators);
@@ -93,6 +94,7 @@ function calculateRPN(expression:string) {
case '≤': stack.push(a <= b ? 1 : 0); break;
case '≥': stack.push(a >= b ? 1 : 0); break;
case '=': stack.push(a === b ? 1 : 0); break;
case '!': stack.push(b ? 0 : 1); break;
}
}
});