With a while loop:

We can cut down on the number of operations by recognizing that we don't need to do len(str)-1 iterations. Instead of using just one pointer that simply iterates through the string from its end, why not use two?
xxxxxxxxxx22
function isPalindrome(str) { let left = 0; let right = str.length - 1; let leftChar; let rightChar;​ while (left < right) { leftChar = str.charAt(left); rightChar = str.charAt(right);​ if (leftChar == rightChar) { left++; right--; } else { return false; } }​ return true;}​console.log(isPalindrome('racecar'));OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment


