Skip to content

Commit 7c571ed

Browse files
committed
Create Letter Capitalize
1 parent ed5229e commit 7c571ed

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Letter Capitalize

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy