(str)
| 15 | * and the case of the characters doesn't matter |
| 16 | */ |
| 17 | const alphaNumericPalindrome = (str) => { |
| 18 | if (typeof str !== 'string') { |
| 19 | throw new TypeError('Argument should be string') |
| 20 | } |
| 21 | |
| 22 | // removing all the special characters and turning everything to lowercase |
| 23 | const newStr = str.replace(/[^a-z0-9]+/gi, '').toLowerCase() |
| 24 | const midIndex = newStr.length >> 1 // x >> y = floor(x / 2^y) |
| 25 | |
| 26 | for (let i = 0; i < midIndex; i++) { |
| 27 | if (newStr.at(i) !== newStr.at(~i)) { |
| 28 | // ~n = -(n + 1) |
| 29 | return false |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | return true |
| 34 | } |
| 35 | |
| 36 | export default alphaNumericPalindrome |
no outgoing calls
no test coverage detected