-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Adding an algorithm AlphaNumericPalindrome from freecodecamp #769
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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 think I have done all my checks of naming convention and ES6 syntax among others.
can I get a review and workflow approval please |
@cclauss Would you consider this as a proper algorithm? |
I don’t do JavaScript so I cannot comment on efficiency but I would have written this as It does however seem to fit the definition of an algorithm unless I am missing something. |
Yes this can be done in two line in JS as well but, this repository being beginner friendly, I wanted to make it as simple as possible, and if you not include the comments and empty lines this function only takes 8 lines |
This error that is popping up saying "unnecessary escape character" in file "Javascript\String\test\AlphaNumericPalindrome.test.js" at lines 8 and 12 is actually inside a string and is a test case requirement, so I don't think this error is any significant in this case. |
A Python version with tests included… from string import ascii_letters, digits
def is_alphanumeric_palendrome(s: str) -> bool:
"""
To test, run: `python3 -m doctest v alphanumeric_palendrome.py`
>>> is_alphanumeric_palendrome("eye")
True
>>> is_alphanumeric_palendrome("0_0 (: /-\ :) 0-0")
True
>>> is_alphanumeric_palendrome("five|\_/|four")
False
>>> is_alphanumeric_palendrome("A man, a plan, a canal. Panama")
True
>>> is_alphanumeric_palendrome(" eye for of 1 eye.")
False
"""
s = "".join(char for char in s if char in ascii_letters + digits).lower()
return s == "".join(reversed(s)) |
For my edification, can you please show me here? |
const alphaNumericPlaindrome = (str) => {
const string = str.replace(/[^a-zA-Z0-9]*/g, '').toLowerCase()
return string === string.split('').reverse().join('')
} Here you go, this will work exactly as your Python code but there is nothing like doctest in js so... |
We actually removed all the doctests and migrated all of them to jest. Since it is a proper algorithm, I am marking it as valid. |
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 format your code using standard.js
.
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.
fixed it
Welcome to JavaScript community
Describe your change:
Checklist:
Example:
UserProfile.js
is allowed butuserprofile.js
,Userprofile.js
,user-Profile.js
,userProfile.js
are notFixes: #{$ISSUE_NO}
.