FE-Interview
FE-Interview copied to clipboard
手写代码实现`kuai-shou-front-end=>KuaiShouFrontEnd`
扫描下方二维码,获取答案以及详细解析,同时可解锁800+道前端面试题。
'kuai-shou-front-end'.split('-').map(item => item.substr(0, 1).toUpperCase() + item.substr(1)).join('')
/*
手写代码实现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'))
function transformCaseToCamel(str){
const reg = /\-([a-z])/g;
return str.replace(reg, (match, $1) => {
return $1.toUpperCase();
})
}
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(""))
'kuai-shou-front-end'.replace(/(?:\b|-)(\w)/g, (_,v)=>v.toUpperCase())