Skip to content

Commit af6133c

Browse files
committed
resolve: removed while loop
1 parent 5958e31 commit af6133c

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

String/AlphaNumericPalindrome.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ const alphaNumericPalindrome = (str) => {
2121

2222
// removing all the special characters and turning everything to lowercase
2323
const newStr = str.replace(/[^a-z0-9]+/ig, '').toLowerCase()
24-
let fromMidIndex = newStr.length >> 1
24+
const midIndex = newStr.length >> 1
2525

26-
while (fromMidIndex--) {
27-
if (newStr.at(fromMidIndex) !== newStr.at(~fromMidIndex)) { // ~n = -(n + 1)
26+
for (let i = 0; i < midIndex; i++) {
27+
if (newStr.at(i) !== newStr.at(~i)) { // ~n = -(n + 1)
2828
return false
2929
}
3030
}

0 commit comments

Comments
 (0)