题解 | #字符串变形#
字符串变形
http://www.nowcoder.com/practice/c3120c1c1bc44ad986259c0cf0f0b80e
function trans(s, n) {
let arr = s.split(/\s/);
let res = [];
let temp;
while (arr.length) {
temp = arr.pop()
temp = temp.split('')
temp.forEach((word,i) => {
if (/[a-z]/.test(word)) {
temp[i] = word.toUpperCase()
}else if (/[A-Z]/.test(word)) {
temp[i] = word.toLowerCase()
}
});
res.push(temp);
res.push(' ')
}
res.pop()
res = res.toString().replace(/,/g,'')
return res
}
module.exports = {
trans : trans
}