# 回文
const palindrome = (str: string) => {
if (str.length < 2) {
return false;
}
let i = 0,
j = str.length - 1;
const reg = /[a-zA-Z]/;
let result = true;
while (result && i < j) {
if (reg.test(str[i]) && reg.test(str[j])) {
result = str[i].toLocaleUpperCase() === str[j].toLocaleUpperCase();
} else {
result = str[i] === str[j];
}
i++;
j--;
}
console.log(result);
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23