Determine whether an integer is a palindrome. Do this without extra space. - Javascript Number Operation

Javascript examples for Number Operation:Number Algorithm

Description

Determine whether an integer is a palindrome. Do this without extra space.

Demo Code


/*// w w w .j  a  v a  2  s .  co  m
Determine whether an integer is a palindrome. Do this without extra space.
*/

function isPalindrome(x) {
  let reversed, original
  let arr = x.toString().split('').map(function(y){
    return parseInt(y)
  })

  original = parseInt(arr.join(''))
  reversed = parseInt(arr.reverse().join(''));

  if (reversed === original) {
    return true
  } else { return false };
}

Related Tutorials