Videos
var isPalindrome = function(s) {
let leftPointer = 0;
let rightPointer = s.length - 1;
while (leftPointer < rightPointer) {
while (leftPointer < rightPointer && !(alphaNumChecker(s[leftPointer]))) {
leftPointer++;
}
while (rightPointer > leftPointer && !(alphaNumChecker(s[rightPointer]))) {
rightPointer--;
}
if (toLowerCase(s[leftPointer]) !== toLowerCase(s[rightPointer])) {
return false;
}
leftPointer++;
rightPointer--;
}
return true;
};
var alphaNumChecker = function(char) {
if (!(char > 47 && char < 58) && // numeric (0-9)
!(char > 64 && char < 91) && // upper alpha (A-Z)
!(char > 96 && char < 123)) { // lower alpha (a-z)
return false;
}
return true;
}
var toLowerCase = function(code) {
if (code >= 65 && code <= 90) {
return code + 32
}
else {
return code
}
}
This is what I got so far using a neetcode tutorial as a guide which is done in Python. This is JS of course. It runs true on "race a car" and I'm not sure why. Spent like 2 hours trying different things, obviously it's not detecting two letters are not the same for some reason.