Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added BasicPrefixSum algorithm and tests #1786

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

Open
mbatwc113114 wants to merge 5 commits into TheAlgorithms:master
base: master
Choose a base branch
Loading
from mbatwc113114:master
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: correct spelling errors in SubsequenceRecursive.js and AlphaNume...
...ricPalindrome.js
  • Loading branch information
mbatwc113114 committed Jul 30, 2025
commit c3a85b6bc58d7ad0e61b9a02a23e853763683521
16 changes: 9 additions & 7 deletions String/AlphaNumericPalindrome.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
/**
* @function alphaNumericPalindrome
* @description alphaNumericPalindrome should return true if the string has alphanumeric characters that are palindrome irrespective of special characters and the letter case.
* @description alphaNumericPalindrome should return true if the string has alphanumeric characters that form a palindrome,
* regardless of special characters and letter case.
* @param {string} str the string to check
* @returns {boolean}
* @see [Palindrome](https://en.wikipedia.org/wiki/Palindrome)
* @example
* The function alphaNumericPalindrome() receives a string with varying formats
* like "racecar", "RaceCar", and "race CAR"
* like "racecar", "RaceCar", and "race CAR".
* The string can also have special characters
* like "2A3*3a2", "2A3 3a2", and "2_A3*3#A2"
* like "2A3*3a2", "2A3 3a2", and "2_A3*3#A2".
*
* But the catch is, we have to check only if the alphanumeric characters
* are palindrome i.e remove spaces, symbols, punctuations etc
* and the case of the characters doesn't matter
* form a palindrome, i.e., remove spaces, symbols, punctuation, etc.
* The case of the characters doesn't matter.
*/
const alphaNumericPalindrome = (str) => {
if (typeof str !== 'string') {
throw new TypeError('Argument should be string')
}

// removing all the special characters and turning everything to lowercase
// Remove all non-alphanumeric characters and convert to lowercase
const newStr = str.replace(/[^a-z0-9]+/gi, '').toLowerCase()

const midIndex = newStr.length >> 1 // x >> y = floor(x / 2^y)

for (let i = 0; i < midIndex; i++) {
if (newStr.at(i) !== newStr.at(~i)) {
// ~n = -(n + 1)
// ~n = -(n + 1), used to get characters from the end
return false
}
}
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /