题解 | #字符串变形#
字符串变形
http://www.nowcoder.com/practice/c3120c1c1bc44ad986259c0cf0f0b80e
function trans(str){
str=str.split(' ')
let res=[]
while(str.length){
let temp=str.pop()
let temp1=temp.split('')
temp1.forEach((item,index,arr)=>{
if(/[a-z]/.test(item)){
arr[index]=item.toUpperCase()
}else if(/[A-Z]/.test(item)){
arr[index]=item.toLowerCase()
}
})
temp1=temp1.join('')
res.push(temp1)
}
console.log(res);
return res.join(' ')
}
module.exports = { trans : trans }