Skip to content

Commit 15b0d2d

Browse files
committed
second commit. Submission of weekly challenges set mvdoyle#2.
1 parent 1e7372d commit 15b0d2d

12 files changed

Lines changed: 108 additions & 10 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 108 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,156 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34

45
namespace ChallengesWithTestsMark8
56
{
67
public class ChallengesSet02
78
{
89
public bool CharacterIsALetter(char c)
910
{
10-
throw new NotImplementedException();
11+
return char.IsLetter(c);
1112
}
1213

1314
public bool CountOfElementsIsEven(string[] vals)
1415
{
15-
throw new NotImplementedException();
16+
if (vals.Length % 2 ==0)
17+
{
18+
return true;
19+
}
20+
else
21+
{
22+
return false;
23+
}
24+
1625
}
1726

1827
public bool IsNumberEven(int number)
1928
{
20-
throw new NotImplementedException();
29+
if (number % 2 == 0)
30+
{
31+
return true;
32+
}
33+
else
34+
{
35+
return false;
36+
}
2137
}
2238

2339
public bool IsNumberOdd(int num)
2440
{
25-
throw new NotImplementedException();
41+
if (num % 2 != 0)
42+
{
43+
return true;
44+
}
45+
else
46+
{
47+
return false;
48+
}
2649
}
2750

2851
public double SumOfMinAndMax(IEnumerable<double> numbers)
2952
{
30-
throw new NotImplementedException();
53+
if (numbers == null)
54+
{
55+
return 0;
56+
}
57+
if (numbers.Count() == 0)
58+
{
59+
return 0;
60+
}
61+
return numbers.Min() + numbers.Max();
62+
// return numbers?.Any() ?? false ? numbers.Min() + numbers.Max() : new double { };
3163
}
3264

3365
public int GetLengthOfShortestString(string str1, string str2)
3466
{
35-
throw new NotImplementedException();
67+
if (str1.Length < str2.Length)
68+
{
69+
return str1.Length;
70+
}
71+
else if (str1 == str2)
72+
{
73+
return 0;
74+
}
75+
else
76+
{
77+
return str2.Length;
78+
}
79+
// return new int {str1.Length, str2.Length}.Min();
3680
}
3781

3882
public int Sum(int[] numbers)
3983
{
40-
throw new NotImplementedException();
84+
if (numbers == null)
85+
{
86+
return 0;
87+
}
88+
89+
int sum = 0;
90+
91+
for (int i = 0; i < numbers.Length; i++)
92+
{
93+
sum += numbers[i];
94+
}
95+
96+
return sum;
97+
// return numbers?.Sum() ?? 0;
4198
}
4299

43100
public int SumEvens(int[] numbers)
44101
{
45-
throw new NotImplementedException();
102+
if (numbers == null)
103+
{
104+
return 0;
105+
}
106+
107+
int sumEven = 0;
108+
109+
for (int i = 0; i < numbers.Length; i++)
110+
{
111+
if (numbers[i] % 2 == 0)
112+
{
113+
sumEven += numbers[i];
114+
}
115+
}
116+
return sumEven;
117+
// return numbers?.Sum(x => x % 2 == 0 ? x : 0) ?? 0;
46118
}
47119

48120
public bool IsSumOdd(List<int> numbers)
49121
{
50-
throw new NotImplementedException();
122+
if (numbers == null)
123+
{
124+
return false;
125+
}
126+
return numbers.Sum() % 2 != 0;
51127
}
52128

53129
public long CountOfPositiveOddsBelowNumber(long number)
54130
{
55-
throw new NotImplementedException();
131+
//var count = 0;
132+
133+
// if (number == 1 || number <= 0)
134+
// {
135+
// return 0;
136+
// }
137+
// for (long i = number; i > 0; i--)
138+
// {
139+
// if(i % 2 ==0)
140+
// {
141+
// count++;
142+
// }
143+
// }
144+
// return count;
145+
//}
146+
if (number <= 0)
147+
{
148+
return 0;
149+
}
150+
else
151+
{
152+
return number / 2;
153+
}
56154
}
57155
}
58156
}
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)