题解 | #字符串变形#

字符串变形

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 }

全部评论

相关推荐

菜菜狗🐶:双非之光
找工作,你会甘心进小厂还...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务