题目:
    给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。
    说明:本题中,我们将空字符串定义为有效的回文串。

    1. functionisPalindrome(s: string): boolean {
    2. if (!s) returntrue;
    3. constfilterFn=function (str: string): string {
    4. constarray=str.split("");
    5. returnarray
    6. .filter((item) => {
    7. constpattern= /\d|[a-z]/;
    8. returnpattern.test(item);
    9. })
    10. .join("");
    11. };
    12. s=filterFn(s.toLowerCase());
    13. consts2=filterFn(s.split("").reverse().join("").toLowerCase());
    14. if (s===s2) returntrue;
    15. returnfalse;
    16. }
    functionisPalindrome2(s: string): boolean {
      s=s.toLowerCase();
      constpattern= /\d|[a-z]/;
      constfn=function (index: number, type: string): number {
        if (!pattern.test(s[index])) {
          type==="left"?index++:index--;
          returnfn(index, type);
        }
        returnindex;
      };
      letleft=fn(0, "left");
      letright=fn(s.length-1, "right");
      while (left<right) {
        if (s[left] !==s[right]) returnfalse;
        left=fn(left++, "left");
        right=fn(right--, "right");
      }
      return true;
    }