Skip to content

Commit

Permalink
feat(JadenCasing): add solution.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusViniciusSS committed Mar 7, 2023
1 parent 368dc22 commit a3f4cec
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Text;

namespace CodeWarsChallenges.Strings._7kyu.Jaden_Casing_Strings;

public static class JadenCasing
{
public static string ToJadenCase(string phrase)
{
var words = phrase.Split(" ");

var builder = new StringBuilder(phrase.Length);

for (int i = 0; i < words.Length; i++)
{
if (!char.IsLetter(words[i][0]) || char.IsUpper(words[i][0]))
{
builder.Append(words[i]);

if ((i + 1) == words.Length)
continue;

builder.Append(' ');
continue;
}

builder.Append((char)(words[i][0] - 32));
builder.Append(words[i][1..]);

if ((i + 1) == words.Length)
continue;

builder.Append(' ');
}

return builder.ToString();
}
}

0 comments on commit a3f4cec

Please sign in to comment.