precedence function

int precedence(
  1. String operator
)

Returns an integer representing the precedence level of the given operator.

This function returns 1 for addition and subtraction operators ('+' and '-') and 2 for multiplication and division operators ('*', '/', '×', and '÷'). For any other operator, the function returns 0.

Implementation

int precedence(String operator) {
  switch (operator) {
    case '+':
    case '-':
      return 1;
    case '*':
    case '/':
    case '×':
    case '÷':
      return 2;
  }

  // If the operator is anything else, return 0.
  return 0;
}