js 回文数
getreverNum(num){ console.log('num----------'+num) let numStr = num.toString(); let numStrRever = numStr.split('').reverse().join('') console.log('numStrRever----'+numStrRever) let preZeroNum = 0 ; for(let i = 0 ;i<numStrRever.length;i++){ let item = numStrRever.substr(i,1); if((item==0)&&(i-preZeroNum==0)){ preZeroNum ++ ; } } let reverNum = numStrRever; if(preZeroNum>0){ reverNum = numStrRever.substr(preZeroNum,numStrRever.length-preZeroNum) } console.log('reverNum----'+parseInt(reverNum)) return parseInt(reverNum) ; },
调用检验:
let num = that.getreverNum(1234) ; num = that.getreverNum(12345) ; num = that.getreverNum(126000) ; num = that.getreverNum(12700) ; num = that.getreverNum(123401) ; num = that.getreverNum(123401) ;