简体   繁体   English

无法敲定 function 骆驼案

[英]Can't finalize the function Camel Case

I can't understand where is first word on output..我不明白 output 的第一个字在哪里..

function camelCase(str){

let string = '';
let arr = str.split(' ');
let oneStr = '';
let twoStr = '';
for (let i = 0; i < arr.length; i++) {
    
string1 = arr[i] ;

oneStr = string1[0].toUpperCase() + string1.slice(1);

}

return oneStr;
}

console.log(camelCase('camel case'));

Output: Case Output:案例

Help please to finalize the code请帮助完成代码

On this line, use += operator to concatenate the strings:在此行中,使用+=运算符连接字符串:

oneStr += string1[0].toUpperCase() + string1.slice(1);

actually you assigned the result to string1 in each iteration, instead use += operator实际上,您在每次迭代中都将结果分配给了string1 ,而不是使用 += 运算符

 function camelCase(str){ let string = ''; let arr = str.split(' '); let oneStr = ''; let twoStr = ''; for (let i = 0; i < arr.length; i++) { string1 = arr[i]; oneStr += string1[0].toUpperCase() + string1.slice(1); } return oneStr; } console.log(camelCase('camel case'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM