Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 131 additions & 7 deletions WorkingWithText/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,91 @@ public static class WorkingWithText
// to see if there are duplicates. If so, return bool True; otherwise, return bool False.
public static bool AreThereDuplicates(string hyphenNum)
{
return default;
bool result = false;
try
{
List<int> nums = hyphenNum.Split('-').Select(int.Parse).ToList();

for (int i = 0; i < hyphenNum.Count(); i++)
{
for (int j = 0; j < nums.Count(); j++)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to run the full length of array each time?

{
try
{
if (i != j)
{
if (Convert.ToInt32(nums[i]) == Convert.ToInt32(nums[j]))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need Convert.ToInt32()'s

{
result = true;
return result;
}
}
}
catch

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's sarcastic

{
}
}
}
}
catch
{
return result;
}

//char[] hyphenCheck = hyphenNum.ToCharArray();
//result = Char.IsNumber(hyphenCheck[0]);
//result = Char.IsNumber(hyphenCheck[hyphenCheck.Length - 1]);
//for (int i = 0; i < hyphenCheck.Length; i++)
//{
// try
// {
// if (Convert.ToString(hyphenCheck[i]) != "-" || Char.IsNumber(hyphenCheck[0]) == false)
// {
// result = false;
// break;
// }
// else if (hyphenCheck[i] == hyphenCheck[i + 1])
// {
// result = false;
// break;
// }
// }
// catch
// {

// }
//}
return result;
}

// 2- Write a method that accepts a string of numbers separated by a hyphen. If the input
// is NOT in the correct format OR is NOT consecutive then return bool False. If the format
// is correct AND the numbers are consecutive, return bool True. For
// example, if the input is "5-6-7-8-9" or "20-19-18-17-16", return bool True.
// Do not use .Sort, it will cause the test to pass when it actually does not.
public static bool IsConsecutive(string hyphenNum)
{
return default;
bool isConsecutiveAcending = false;
bool isConsecutiveDecending = false;

try
{
List<int> nums = hyphenNum.Split('-').Select(int.Parse).ToList();
isConsecutiveAcending = !nums.Select((i, j) => i - j).Distinct().Skip(1).Any();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the .Any() there?

isConsecutiveDecending = !nums.Select((i, j) => i + j).Distinct().Skip(1).Any();
}
catch
{
return false;
}
if (isConsecutiveAcending == true || isConsecutiveDecending == true)
{
return true;
}
else
{
return false;
}
}

// 3- Write a method that accepts a string of a time 24-hour time format
Expand All @@ -30,7 +104,21 @@ public static bool IsConsecutive(string hyphenNum)
// consider it as False. Make sure that its returns false if any letters are passed.
public static bool IsValidTime(string hyphenNum)
{
return default;
bool result = false;
DateTime dt;
try
{
dt = Convert.ToDateTime(hyphenNum);
if(hyphenNum == dt.ToString("HH:mm"))
{
result = true;
}

}
catch
{
}
return result;
}

// 4- Write a method that accepts a string of a few words separated by a space. Use the
Expand All @@ -40,15 +128,51 @@ public static bool IsValidTime(string hyphenNum)
// Trim off unneeded spaces.
public static string PascalConverter(string aFewWords)
{
return default;
if(aFewWords == "" || aFewWords == null)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could have used string.NullOrEmpty()

{
return aFewWords;
}
string lowerCase = aFewWords.ToLower();
string[] separated = aFewWords.Split(' ');
string temp = "";
string result = "";
for (int i = 0; i < separated.Count(); i++)
{
temp = separated[i];
if (temp.Length > 1)
{
result += char.ToUpper(temp[0]) + temp.Substring(1).ToLower();
}
else
{
result += temp.ToUpper();
}
}
return result;
}

// 5- Write a method that accepts an English word. Count the number of vowels
// (a, e, i, o, u) in the word. So, if the user enters "inadequate", the program should
// return 6.
public static int VowelCounter(string aWord)
public static int VowelCounter(string aWord)
{
return default;
char[] vowels = new char[] { 'a', 'e', 'i', 'o', 'u' };
aWord = aWord.ToLower();
char[] characters = aWord.ToCharArray();
int vowelCount = 0;
aWord = aWord.ToLower();

for(int i = 0; i<characters.Length; i++)
{
for(int j = 0; j<vowels.Length; j++)
{
if(vowels[j] == characters[i])
{
vowelCount++;
}
}
}
return vowelCount;
}
}

Expand Down