File tree Expand file tree Collapse file tree 1 file changed +19
-26
lines changed Expand file tree Collapse file tree 1 file changed +19
-26
lines changed Original file line number Diff line number Diff line change 1- class isValidPalindrome {
2- constructor ( string ) {
3- this . string = string ;
4- }
5- isPalindrome ( string ) {
6- let left = 0 ;
7- let right = string . length - 1 ;
8- while ( left < right ) {
9- while ( left < right && this . isAlphaNumeric ( string [ left ] ) ) {
10- left ++
11- }
12- while ( right > left && this . isAlphaNumeric ( string [ right ] ) ) {
13- right --
14- }
15- if ( string [ left ] . toLowerCase ( ) != string [ right ] . toLowerCase ( ) ) {
16- return false ;
17- }
18- left ++
19- right --
1+ var isPalindrome = function ( s ) {
2+ let l = 0 , r = s . length - 1 ;
3+ while ( l < r ) {
4+ while ( l < r && ! isAlphaNumeric ( s [ l ] ) ) {
5+ l ++ ;
6+ }
7+ while ( r > l && ! isAlphaNumeric ( s [ r ] ) ) {
8+ r -- ;
209 }
21- return true
10+ if ( s [ l ] . toLowerCase ( ) !== s [ r ] . toLowerCase ( ) ) return false ;
11+ l ++ ;
12+ r -- ;
2213 }
14+ return true ;
2315
24- isAlphaNumeric ( c ) {
25- return ( 'A' . charCodeAt ( 0 ) <= c . charCodeAt ( 0 ) <= 'Z' . charCodeAt ( 0 ) ||
26- 'a' . charCodeAt ( 0 ) <= c . charCodeAt ( 0 ) <= 'z' . charCodeAt ( 0 ) ||
27- '0' . charCodeAt ( 0 ) <= c . charCodeAt ( 0 ) <= '9' . charCodeAt ( 0 ) )
16+ function isAlphaNumeric ( c ) {
17+ return (
18+ ( 'A' . charCodeAt ( 0 ) <= c . charCodeAt ( 0 ) && c . charCodeAt ( 0 ) <= 'Z' . charCodeAt ( 0 ) ) ||
19+ ( 'a' . charCodeAt ( 0 ) <= c . charCodeAt ( 0 ) && c . charCodeAt ( 0 ) <= 'z' . charCodeAt ( 0 ) ) ||
20+ ( '0' . charCodeAt ( 0 ) <= c . charCodeAt ( 0 ) && c . charCodeAt ( 0 ) <= '9' . charCodeAt ( 0 ) )
21+ )
2822 }
29-
30- }
23+ } ;
You can’t perform that action at this time.
0 commit comments