Skip to content

Commit ace593c

Browse files
committed
Added class and test method for Letter Capitalize code challenge.
1 parent d722ab3 commit ace593c

File tree

4 files changed

+56
-11
lines changed

4 files changed

+56
-11
lines changed

Coderbyte_CSharp/1 Easy Challenges/ChangeLetter.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,32 @@ public string LetterChanges(string str)
4747

4848
return result;
4949
}
50+
51+
// Have the function LetterCapitalize(str) take the str parameter being passed
52+
// and capitalize the first letter of each word. Words will be separated by
53+
// only one space.
54+
public string LetterCapitalize(string str)
55+
{
56+
string result = String.Empty;
57+
char[] chars = str.ToCharArray();
58+
59+
60+
for ( int index = 0; index < chars.Length; index++)
61+
{
62+
if (index == 0 && Char.IsLower(str[index]))
63+
{
64+
chars[index] = Char.ToUpper(chars[index]);
65+
}
66+
67+
if (index > 0 && chars[index - 1] == ' ')
68+
{
69+
chars[index] = Char.ToUpper(chars[index]);
70+
}
71+
}
72+
73+
result = new string(chars);
74+
75+
return result;
76+
}
5077
}
5178
}

Coderbyte_CSharp/1 Easy Challenges/EasyChallenges.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Check Numbers 02/10/2021 NumberCheck
88
Find Intersection 02/11/2021 StringIntersection
99
First Factorial 02/22/2021 Factorial
1010
First Reverse 02/22/2021 StringReverse
11-
Letter Capitalize
11+
Letter Capitalize 02/22/2021 ChangeLetter
1212
Letter Changes 02/22/2021 ChangeLetter
1313
Longest Word
1414
Moving Median

Coderbyte_CSharp/Program.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,23 @@ static void Main(string[] args)
2626
tc.Test_FirstFactorial();
2727
tc.Test_FirstReverse();
2828
tc.Test_LetterChanges();
29+
tc.Test_LetterCapitalize();
2930

3031
// Medium
3132
Console.WriteLine("Medium Code Challenges:");
32-
tc.Test_Consecutive();
33-
tc.Test_KUniqueCharacters();
34-
tc.Test_NumberEncoding();
35-
tc.Test_PrimeMover();
36-
tc.Test_MinWindowSubstring();
37-
tc.Test_RunLength();
38-
tc.Test_StringReduction();
39-
//tc.Test_TreeConstructor();
33+
//tc.Test_Consecutive();
34+
//tc.Test_KUniqueCharacters();
35+
//tc.Test_NumberEncoding();
36+
//tc.Test_PrimeMover();
37+
//tc.Test_MinWindowSubstring();
38+
//tc.Test_RunLength();
39+
//tc.Test_StringReduction();
40+
////tc.Test_TreeConstructor();
4041

4142
// Hard
4243
Console.WriteLine("Hard Code Challenges:");
43-
tc.Test_KaprekarsConstant();
44-
tc.Test_Determinant();
44+
//tc.Test_KaprekarsConstant();
45+
//tc.Test_Determinant();
4546
}
4647
}
4748
}

Coderbyte_CSharp/TestChallenge.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,23 @@ public void Test_LetterChanges()
199199
Console.WriteLine("Output: {0}", changer.LetterChanges(str));
200200
Console.WriteLine();
201201
}
202+
public void Test_LetterCapitalize()
203+
{
204+
ChangeLetter changer = new ChangeLetter();
205+
206+
string str = "applez";
207+
208+
Console.WriteLine("Letter Capitalize:");
209+
Console.WriteLine("Input: {0}", str);
210+
Console.WriteLine("Output: {0}", changer.LetterCapitalize(str));
211+
Console.WriteLine();
212+
213+
str = "coder byte";
214+
215+
Console.WriteLine("Input: {0}", str);
216+
Console.WriteLine("Output: {0}", changer.LetterCapitalize(str));
217+
Console.WriteLine();
218+
}
202219
#endregion
203220

204221
#region Medium Challenges

0 commit comments

Comments
 (0)