We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ae63e44 commit a08fb45Copy full SHA for a08fb45
string_manipulation_algorithms/capitalizeFirstLetter_JS_Way.ts
@@ -0,0 +1,19 @@
1
+// function accepts a string containing words and returns a string which
2
+// has every word capitalized (i.e. first letter is a capital)
3
+
4
+// O(n)
5
+function capitalizeFirstLetter_JS_Way(inputString: string): string {
6
+ const words: string[] = inputString.split(' ');
7
8
+ const capitalizedWords: string[] = words.map(
9
+ (word) => word.slice(0, 1).toUpperCase() + word.slice(1),
10
+ );
11
12
+ return capitalizedWords.join(' ');
13
+}
14
15
+// should return: I Am A String
16
+console.log(capitalizeFirstLetter_JS_Way('i am a string'));
17
18
+// should return: I Am A String With Comma, And Stuff!
19
+console.log(capitalizeFirstLetter_JS_Way('i am a string with comma, and stuff!'));
0 commit comments