isPalindrome function

bool isPalindrome(
  1. int n
)

Checks if a number n is a palindrome.

Example:

final result = isPalindrome(545);
print(result); // prints: true

Implementation

bool isPalindrome(int n) {
  int r, sum = 0, temp;
  temp = n;
  while (n > 0) {
    r = n % 10;
    sum = (sum * 10) + r;
    n = n ~/ 10;
  }
  if (temp == sum) return true;
  return false;
}