题解 | #字符逆序#
字符逆序
http://www.nowcoder.com/practice/cc57022cb4194697ac30bcb566aeb47b
let str = readline(); function getStr(str){ let res; let returnStr; let resArr = []; if(/[^a-zA-Z\s]/g.test(str)){ throw new Error('输入值错误'); } let reg = /(\s+)?([a-zA-Z]+)/gi; returnStr = str.match(reg); for(let i = returnStr.length - 1; i>=0; i--){ resArr.push(returnStr[i].split('').reverse().join('')) } console.log(resArr.join('')); } getStr(str);