Studying all day long)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.3 KiB

2 years ago
export type Operator =
| '+'
| '-'
| '/'
| '%'
| '*'
| '**'
| '&'
| '|'
| '>>'
| '>>>'
| '<<'
| '^'
| '=='
| '==='
| '!='
| '!=='
| 'in'
| 'instanceof'
| '>'
| '<'
| '>='
| '<=';
export default function binaryOperation(
operator: Operator,
left: any,
right: any,
): any {
switch (operator) {
case '+':
return left + right;
case '-':
return left - right;
case '/':
return left / right;
case '%':
return left % right;
case '*':
return left * right;
case '**':
return left ** right;
case '&':
return left & right;
case '|':
return left | right;
case '>>':
return left >> right;
case '>>>':
return left >>> right;
case '<<':
return left << right;
case '^':
return left ^ right;
case '==':
return left == right;
case '===':
return left === right;
case '!=':
return left != right;
case '!==':
return left !== right;
case 'in':
return left in right;
case 'instanceof':
return left instanceof right;
case '>':
return left > right;
case '<':
return left < right;
case '>=':
return left >= right;
case '<=':
return left <= right;
}
}