function titleCase(str) {
  var aa = str.toLowerCase();
  var arr = aa.split(" ");
  var array = [];
  for (var i in arr) {
    cc = arr[i].replace(/^\S/, arr[i][0].toUpperCase());
    array.push(cc);
  }
  
  return array.join(" ");
}

titleCase("I'm a little tea pot");

  

titleCase("I'm a little tea pot") 应该返回一个字符串
 
titleCase("I'm a little tea pot") 应该返回 "I'm A Little Tea Pot".
 
titleCase("sHoRt AnD sToUt") 应该返回 "Short And Stout".
 
titleCase("HERE IS MY HANDLE HERE IS MY SPOUT") 应该返回 "Here Is My Handle Here Is My Spout".

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-17
  • 2021-11-16
  • 2022-12-23
  • 2021-09-28
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-20
  • 2022-01-31
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案