- Notifications
You must be signed in to change notification settings - Fork2.4k
Update 0125-valid-palindrome.js#2535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Added a new 2 pointer implementation that doesn't use RegEx (only primitives), and no copying of strings.
aakhtar3 left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Check suggestions
javascript/0125-valid-palindrome.js Outdated
| varisPalindrome=function(s){ | ||
| constisAlpha=c=>(c.toLowerCase()>='a'&&c.toLowerCase()<='z')||c>='0'&&c<='9' | ||
| leti=0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Suggestion: use a more readable variable name like 'left' and 'right'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I did some refactoring per your suggestion
javascript/0125-valid-palindrome.js Outdated
| letj=s.length-1; | ||
| while(i<j){ | ||
| if(!isAlpha(s.charAt(i))){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Suggestion: avoid else
| if(!isAlpha(s.charAt(i))){ | |
| if(isInvalid)returnfalse; | |
| if(canMoveLeft){left++;continue;} | |
| if(canMoveRight){right--;continue;} | |
| left++; | |
| right--; |
acidbluebriggsJun 6, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Please check current changes. I have introduced some variables for clarity.
* Clarified some variable and internal function names* Removed if/else conditions* Introduced new variables to increase clarity
Uh oh!
There was an error while loading.Please reload this page.
Added a new 2 pointer implementation that doesn't use RegEx (only primitives), and doesn't create new strings.