isPalindrom static method

bool isPalindrom(
  1. String string
)

Checks if string is Palindrom.

Implementation

static bool isPalindrom(String string) {
  final cleanString = string
      .toLowerCase()
      .replaceAll(RegExp(r'\s+'), '')
      .replaceAll(RegExp('[^0-9a-zA-Z]+'), '');

  for (var i = 0; i < cleanString.length; i++) {
    if (cleanString[i] != cleanString[cleanString.length - i - 1]) {
      return false;
    }
  }

  return true;
}