Skip to content

Commit c3a85b6

Browse files
committed
fix: correct spelling errors in SubsequenceRecursive.js and AlphaNumericPalindrome.js
1 parent 6534323 commit c3a85b6

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

String/AlphaNumericPalindrome.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
/**
22
* @function alphaNumericPalindrome
3-
* @description alphaNumericPalindrome should return true if the string has alphanumeric characters that are palindrome irrespective of special characters and the letter case.
3+
* @description alphaNumericPalindrome should return true if the string has alphanumeric characters that form a palindrome,
4+
* regardless of special characters and letter case.
45
* @param {string} str the string to check
56
* @returns {boolean}
67
* @see [Palindrome](https://en.wikipedia.org/wiki/Palindrome)
78
* @example
89
* The function alphaNumericPalindrome() receives a string with varying formats
9-
* like "racecar", "RaceCar", and "race CAR"
10+
* like "racecar", "RaceCar", and "race CAR".
1011
* The string can also have special characters
11-
* like "2A3*3a2", "2A3 3a2", and "2_A3*3#A2"
12+
* like "2A3*3a2", "2A3 3a2", and "2_A3*3#A2".
1213
*
1314
* But the catch is, we have to check only if the alphanumeric characters
14-
* are palindrome i.e remove spaces, symbols, punctuations etc
15-
* and the case of the characters doesn't matter
15+
* form a palindrome, i.e., remove spaces, symbols, punctuation, etc.
16+
* The case of the characters doesn't matter.
1617
*/
1718
const alphaNumericPalindrome = (str) => {
1819
if (typeof str !== 'string') {
1920
throw new TypeError('Argument should be string')
2021
}
2122

22-
// removing all the special characters and turning everything to lowercase
23+
// Remove all non-alphanumeric characters and convert to lowercase
2324
const newStr = str.replace(/[^a-z0-9]+/gi, '').toLowerCase()
25+
2426
const midIndex = newStr.length >> 1 // x >> y = floor(x / 2^y)
2527

2628
for (let i = 0; i < midIndex; i++) {
2729
if (newStr.at(i) !== newStr.at(~i)) {
28-
// ~n = -(n + 1)
30+
// ~n = -(n + 1), used to get characters from the end
2931
return false
3032
}
3133
}

0 commit comments

Comments
 (0)