-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisPalindrome.js
48 lines (46 loc) · 935 Bytes
/
isPalindrome.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function alphanumeric(c){
if (c>='a' && c<='z'){
return true
}
if (c>='A' && c<='Z'){
return true
}
if (c>='0' && c<='9'){
return true
}
return false
}
function isPalindrome(s) {
// let i=0
// let j=s.length-1
// while (i<=j){
// if (s[i]!==s[j]){
// return false
// }
// else if (s[i]===s[j]){
// i++
// j--
// }
// return true
// }
let i=0
let j=s.length-1
while (i<=j){
if (alphanumeric(s[i])===false){
i++
continue
}
else if (alphanumeric(s[j])===false){
j--
continue
}
else if (s[i].toLowerCase()!==s[j].toLowerCase()){
return false
}
else if (s[i].toLowerCase()===s[j].toLowerCase()){
i++
j--
}
}
return true
}