const reverseStr = (s) =>{ return s.trim().split('').reverse().join(''); } const readline = require('readline'); const rl = readline.createInterface({ input:process.stdin, output:process.stdout }); rl.on('line',(line) => { console.log(reverseStr(line)) })
双指针
const readline = require('readline'); const rl = readline.createInterface({ input:process.stdin, output:process.stdout }); rl.on('line',(line)=>{ let arr = line.split(''); let l= -1,r = arr.length; while(++l<--r){ [arr[l],arr[r]] = [arr[r],arr[l]] } console.log(arr.join('')) })