FE-Interview icon indicating copy to clipboard operation
FE-Interview copied to clipboard

手写代码实现`kuai-shou-front-end=>KuaiShouFrontEnd`

Open lgwebdream opened this issue 5 years ago • 6 comments

lgwebdream avatar Jul 06 '20 15:07 lgwebdream

扫描下方二维码,获取答案以及详细解析,同时可解锁800+道前端面试题。

lgwebdream avatar Jul 06 '20 15:07 lgwebdream

'kuai-shou-front-end'.split('-').map(item => item.substr(0, 1).toUpperCase() + item.substr(1)).join('')

523451928 avatar Jul 15 '20 10:07 523451928

/* 手写代码实现kuai-shou-front-end=>KuaiShouFrontEnd */

function handler(str){ return str.split('-').map(item=>item.substr(0,1).toUpperCase()+item.substr(1)).join('') }

console.log(handler('kuai-shou-front-end'))

future-builder007 avatar Jul 28 '20 03:07 future-builder007

function transformCaseToCamel(str){
    const reg = /\-([a-z])/g;
    return str.replace(reg, (match, $1) => {
        return $1.toUpperCase();
    })
}

wonggai avatar May 23 '21 07:05 wonggai

let tmp='kuai-shou-front-end'
 let x = tmp.split('-')
 x = x.map((item)=>{
   let t =  item[0].toUpperCase()
   let o = item.split("")
   o.shift()
   
   t=t+o.join("")
   return t
 })
console.log(x.join(""))

或者这样

let tmp='kuai-shou-front-end'
 let x = tmp.split('-')
 x = x.map((item)=>{
   return item.substr(0,1).toUpperCase()+item.substr(1)
 })
console.log(x.join(""))

Alicca-miao avatar Sep 27 '24 12:09 Alicca-miao

'kuai-shou-front-end'.replace(/(?:\b|-)(\w)/g, (_,v)=>v.toUpperCase())

liduzhong avatar Mar 25 '25 01:03 liduzhong