function resolve(n) {
if (n < 0) return false;
var len = 0;
while(Math.pow(10, len) <= n) len++;
if (len === 1) return true;
while(len > 1) {
if (n % 10 !== ~~(n / Math.pow(10, len - 1))) return false;
n = ~~ (n % Math.pow(10, len - 1) / 10);
len -= 2;
}
return true;
}
console.assert(resolve(1221) === true, 1);
console.assert(resolve(1221221) === true, 2);
console.assert(resolve(1234321) === true, 3);
console.assert(resolve(234) === false, 4);
by @barretlee