Title Description
Determine whether an integer is a palindrome. Palindrome correct order (from left to right) and reverse (right to left) reading is the same integer.
method one:
var isPalindrome = function(x) {
var resultArr, resultNum;
resultArr = x.toString().split("");
if(resultArr[0] == "-"){
return false;
}
resultNum = parseInt(resultArr.reverse().join(""));
if(x == resultNum){
return true;
}
return false;
};
Advanced
Method Two:
var isPalindrome = function(x) {
var resultArr = x.toString().split("");
for(var i = 0;i < resultArr.length/2; i++){
if(resultArr[i] != resultArr[resultArr.length-1-i]){
return false;
}
}
return true;
};