This code does not work!
It causes the browser to crash;
Can someone please help me debug this? Not sure what is wrong.
My assumption is I have a pointer at the beginning of the string and the end of the string, And I check if each character is the same, and finish once the end and beginning pointer get to the middle...
But like I said it's not working.
function isPalindrome(string) {
let isStringPalindrome = true;
let left = 0;
let right = string.length - 1;
let middle = Math.floor((left + right)/2);
while(string[left] === string[right]){
left + 1;
right - 1;
if (left === middle && right === middle) {
break;
}
if (string[left] !== string[right]) {
isStringPalindrome = false;
break;
}
}
return isStringPalindrome;
}