-
Notifications
You must be signed in to change notification settings - Fork 8
Update Program.cs #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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++) | ||
| { | ||
| try | ||
| { | ||
| if (i != j) | ||
| { | ||
| if (Convert.ToInt32(nums[i]) == Convert.ToInt32(nums[j])) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need Convert.ToInt32()'s |
||
| { | ||
| result = true; | ||
| return result; | ||
| } | ||
| } | ||
| } | ||
| catch | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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 | ||
|
|
@@ -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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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?