JSFiddle - React, Tailwind, and code Playground

by meddle

JavaScript

var isAlphaNumeric = function(code) {
	if ((code < 48) || (code > 122) || 
	   ((code > 57) && (code < 65)) || 
	   ((code > 90) && (code < 97))   ) {
		return false;
	}
    return true;
}

var isPalindrome = function(s) {

    
    var ln = s.length,
        i = 0, j = ln - 1,
        f, b;
    
    ln = (ln === 0) ? 0 : Math.floor(ln/2) + 1;
    for (; i < ln; i++) {
        f = s.charCodeAt(i);
        b = s.charCodeAt(j);

        if (!isAlphaNumeric(f)) {
            continue;
        }
        while (!isAlphaNumeric(b)) {
            b = s.charCodeAt(--j);
        }
        if (f > 64 && f < 91) {
            f = f + 32;
        }
        if (b > 64 && b < 91) {
            b = b + 32;
        }

        if (b !== f && !(isNaN(b) && isNaN(f))) {
            return false;
        }
        

        j--;
    }
    
    return true;
};

console.log(isPalindrome(" "))