-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTitle_Case_a_Sentence.js
More file actions
25 lines (24 loc) · 967 Bytes
/
Title_Case_a_Sentence.js
File metadata and controls
25 lines (24 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const titleCase = str => str.replace(/\S+\g/, s => s.charAt(0).toUpperCase() + s.slice(1).toLowerCase());
/*
const titleCase = str => str.toLowerCase().split(" ").map(s => s.charAt(0).toUpperCase() + s.slice(1)).join(" ");
*/
/* function titleCase(str) {
return str.toLowerCase().split(" ").map(function (s) {
return s.charAt(0).toUpperCase() + s.slice(1);
}).join(" ");
}
*/
/*
function titleCase(str) {
stringArray = str.toLowerCase().split(" ");
for (var i = 0; i < stringArray.length; i++) {
stringArray[i] = stringArray[i].charAt(0).toUpperCase() + stringArray[i].slice(1);
}
return stringArray.join(" ");
}
*/
titleCase("I'm a little tea pot"); // should return a string.
titleCase("I'm a little tea pot"); // should return "I'm A Little Tea Pot".
titleCase("sHoRt AnD sToUt"); // should return "Short And Stout".
titleCase("HERE IS MY HANDLE HERE IS MY SPOUT");
// should return "Here Is My Handle Here Is My Spout".