Skip to content

Commit 4ed4393

Browse files
committed
Completed Weekly Challenges mvdoyle#2.
1 parent 9f0df23 commit 4ed4393

8 files changed

Lines changed: 69 additions & 7 deletions

File tree

Binary file not shown.
Binary file not shown.

ChallengesWithTestsMark8/ChallengesSet02.cs

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel.Design;
4+
using System.Linq;
35

46
namespace ChallengesWithTestsMark8
57
{
68
public class ChallengesSet02
79
{
810
public bool CharacterIsALetter(char c)
911
{
10-
throw new NotImplementedException();
12+
13+
return Char.IsLetter(c);
14+
1115
}
1216

1317
public bool CountOfElementsIsEven(string[] vals)
1418
{
15-
throw new NotImplementedException();
19+
return vals.Length % 2 == 0;
1620
}
1721

1822
public bool IsNumberEven(int number)
@@ -35,31 +39,89 @@ public bool IsNumberOdd(int num)
3539

3640
public double SumOfMinAndMax(IEnumerable<double> numbers)
3741
{
38-
throw new NotImplementedException();
42+
if (numbers == null || numbers.Count() == 0)
43+
{
44+
return 0;
45+
}
46+
47+
return numbers.Min() + numbers.Max();
3948
}
4049

4150
public int GetLengthOfShortestString(string str1, string str2)
4251
{
43-
throw new NotImplementedException();
52+
var word1 = str1.Length;
53+
var word2 = str2.Length;
54+
55+
if (word1 < word2)
56+
{
57+
return word1;
58+
}
59+
else
60+
{
61+
return word2;
62+
}
4463
}
4564

4665
public int Sum(int[] numbers)
4766
{
48-
throw new NotImplementedException();
67+
var sum = 0;
68+
if(numbers == null || numbers.Count() == 0) { return 0; }
69+
foreach (var number in numbers)
70+
{
71+
sum += number;
72+
}
73+
return sum;
4974
}
5075

5176
public int SumEvens(int[] numbers)
5277
{
53-
throw new NotImplementedException();
78+
var sum = 0;
79+
if (numbers == null)
80+
{
81+
return 0;
82+
}
83+
foreach (var number in numbers)
84+
{
85+
if (number % 2 == 0)
86+
{
87+
88+
sum += number;
89+
}
90+
}
91+
92+
return sum;
93+
94+
95+
5496
}
5597

5698
public bool IsSumOdd(List<int> numbers)
5799
{
58-
throw new NotImplementedException();
100+
if (numbers == null)
101+
{
102+
return false;
103+
}
104+
var sum = 0;
105+
foreach (var number in numbers)
106+
{
107+
sum += number;
108+
}
109+
if (sum % 2 != 0)
110+
{
111+
return true;
112+
}
113+
else
114+
{
115+
return false;
116+
}
59117
}
60118

61119
public long CountOfPositiveOddsBelowNumber(long number)
62120
{
121+
if (number < 0)
122+
{
123+
return 0;
124+
}
63125
return number / 2;
64126
}
65127
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)