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".