Skip to content

Latest commit

 

History

History
21 lines (19 loc) · 500 Bytes

7.md

File metadata and controls

21 lines (19 loc) · 500 Bytes
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