题解 | #单词倒排#
单词倒排
http://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
let str = readline(); function getStr(str){ let res; let returnStr; let resArr = []; let reg = /([a-zA-Z]+)/g; returnStr = str.match(reg); for(let i = returnStr.length - 1; i>=0; i--){ if(returnStr[i].trim().length>20){ throw new Error('输入值错误'); } resArr.push(returnStr[i].trim()) } console.log(resArr.join(' ')); } getStr(str);