Open dengnan123 opened 4 years ago
const str3 = 'test_dany_ha_c_' function func(str) { const arr = str.split('_') const arr1 = [arr[0]] for (let i = 1; i < arr.length; i++) { const v = arr[i] if (v.length) { const key = v[0] const newStr = v.replace(`${key}`, key.toUpperCase()) arr1.push(newStr) } } return arr1.join('') } console.log('test', func(str3))
更多解法 https://github.com/haizlin/fe-interview/issues/12