数组方法
var isPalindrome = function(x) {return x.toString() == x.toString().split('').reverse().join('') ? true : false};
双指针
不需要转成数组类型,字符串可以获取下标,例:const str = ‘hello world’, str[0]即h
Math.floor:向下取整
Math.ceil:向上取整
Math.round:四舍五入
var isPalindrome = function(x) {const temp = x.toString()const length = Math.floor(temp.length / 2)for(let i = 0; i < length; i++){if(temp[i] !== temp[temp.length - i - 1]) return false}return true};
余数重组
首先判定绝对不符合条件的数字,即负数和末位为0且不为0的数
重组余数,实现数字反转
while先判断,再执行语句块,do…while先执行语句块,再判断
var isPalindrome = function(x) {if(x < 0 || (x % 10 === 0 && x !== 0)) return falselet temp = 0, s = xwhile(s){temp = temp * 10 + s % 10s = Math.floor(s /10)}return x === temp};
