Adding an algorithm AlphaNumericPalindrome from freecodecamp#769
Adding an algorithm AlphaNumericPalindrome from freecodecamp#769cclauss merged 7 commits intoTheAlgorithms:masterfrom SyedFasiuddin:master
Conversation
SyedFasiuddin
left a comment
There was a problem hiding this comment.
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. |
raklaptudirm
left a comment
There was a problem hiding this comment.
Please format your code using standard.js.
Welcome to JavaScript community
Describe your change:
Checklist:
Example:
UserProfile.jsis allowed butuserprofile.js,Userprofile.js,user-Profile.js,userProfile.jsare notFixes: #{$ISSUE_NO}.