First solution第一種解法:
Thinking process(思路):
1.turn string into array
2.iterate the array
3.get first letter of each element of array and capitalize it
get the rest letters and lowercase it.
4. join array.
function titleCase(arr){
var getArr = arr.split(" "); //
for(i=0; i< getArr.length; i++){
getArr[i] = getArr[i].charAt(0).toUpperCase() + getArr[i].substring(1).toLowerCase();
}
return getArr.join(" ");
}
titleCase("I'm a little tea pot");
沒有留言:
張貼留言