// 操作数字 翻转
function getSymmetryNum(n) {
const res = []
for (let i = 1; i < n; i++) {
let result = 0
let count = i
while (count > 0) {
result = result * 10 + count % 10
count = parseInt(count / 10)
}
if (i === result) {
res.push(result)
}
}
return res
}
console.time('getSymmetryNum')
const result1 = getSymmetryNum(1000000)
console.timeEnd('getSymmetryNum')
// 操作数组
function getSymmetryNum1(n) {
const res = []
for (let i = 1; i < n; i++) {
const reverseNum = parseInt(i.toString().split('').reverse().join(''))
if (reverseNum === i) {
res.push(i)
}
}
return res
}
console.time('getSymmetryNum1')
const result2 = getSymmetryNum1(1000000)
console.timeEnd('getSymmetryNum1')
console