Is Palindrome (easy)

Return if a number is a palindrome.

function isPalindrome(n) {
  if (n < 0) return false

  let str = String(n)

  for (let i = 0; i < str.length / 2; i++) {
    if (str[i] !== str[str.length - 1 - i]) return false
  }

  return true
}

const x = isPalindrome(111)
const y = isPalindrome(122)
const z = isPalindrome(-121)

console.log(x)
console.log(y)
console.log(z)
Scroll to top