ForeveHG / Frontend-Daily-Interview

学习,尝试回答一些前端面试题
1 stars 0 forks source link

71. 写一个方法把下划线命名转成大驼峰命名 #72

Open ForeveHG opened 3 years ago

ForeveHG commented 3 years ago

题目来源 https://github.com/haizlin/fe-interview/issues/12

ForeveHG commented 3 years ago
function transformCamelCase(name) {
    return name.split('_').map((n, index) => index > 0 ? n.substr(0,1).toUpperCase() + n.substr(1) : n).join('')
}

//测试
transformCamelCase('a_c_def')     //aCDef
transformCamelCase('a_bcd_efg') //a_bcd_efg