File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ /***************************************************************************************
2+ * *
3+ * CODERBYTE BEGINNER CHALLENGE *
4+ * *
5+ * Letter Capitalize *
6+ * Using the JavaScript language, have the function LetterCapitalize(str) take the *
7+ * str parameter being passed and capitalize the first letter of each word. Words *
8+ * will be separated by only one space. *
9+ * *
10+ * SOLUTION *
11+ * I am going to convert the string to an array based on the space character that *
12+ * separates each word. Then I am going to loop through each word in the array and *
13+ * capitalize the first letter of the word. I am going to convert array back to a *
14+ * string to return as the answer.
15+ * *
16+ * Steps for solution *
17+ * 1) Convert string to arry of words by splitting on space. *
18+ * 2) Loop thru each word in the array and convert first letter to uppercase *
19+ * using the charAt(0) value and then appending the remainder of the word *
20+ * using the slice() function *
21+ * 3) Convert array to string with join() function. *
22+ * *
23+ ***************************************************************************************/
24+
25+ function LetterCapitalize(str) {
26+
27+ var arr = str.split(" ");
28+ for (var i = 0; i < arr.length; i++) {
29+ arr[i] = arr[i].charAt(0).toUpperCase() + arr[i].slice(1);
30+ }
31+
32+ return arr.join(" ");
33+
34+ }
You can’t perform that action at this time.
0 commit comments