-
Notifications
You must be signed in to change notification settings - Fork 0
/
EumerableTask.cs
139 lines (112 loc) · 3.15 KB
/
EumerableTask.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;
using System.Collections.Generic;
using System.Linq;
namespace PadawansTask15
{
public class EnumerableTask
{
public IEnumerable<string> GetUppercaseStrings(IEnumerable<string> data)
{
IEnumerator<string> ie = data.GetEnumerator();
List<string> result = new List<string>();
string newItem;
while (ie.MoveNext())
{
string item = ie.Current;
if (!string.IsNullOrEmpty(item))
{
newItem = item.ToUpper();
}
else
{
newItem = item;
}
result.Add(newItem);
}
return result;
}
public IEnumerable<int> GetStringsLength(IEnumerable<string> data)
{
List<int> result = new List<int>();
int temp;
foreach (string e in data)
{
if (e == null)
{
result.Add(0);
}
else
{
result.Add(e.Length);
}
}
return result;
}
public IEnumerable<long> GetSquareSequence(IEnumerable<int> data)
{
long temp;
List<long> result = new List<long>();
foreach (int e in data)
{
temp = e * e;
result.Add(temp);
}
return result;
}
public IEnumerable<string> GetPrefixItems(IEnumerable<string> data, string prefix)
{
List<string> result = new List<string>();
if (prefix == null)
{
throw new ArgumentNullException { };
}
string prefixLow = prefix.ToLower();
string prefixUp = prefix.ToUpper();
foreach (string e in data)
{
if (e == null)
{
}
else if ((e.StartsWith(prefixLow)) || (e.StartsWith(prefixUp)))
{
result.Add(e);
}
}
return result;
}
public IEnumerable<int> Get3LargestItems(IEnumerable<int> data)
{
List<int> list = new List<int>();
int a;
List<int> result = new List<int>();
list.AddRange(data);
list.Sort();
for (int i = 1; i <= 3; i++)
{
if (list.Count == 0)
{
break;
}
else
{
a = list.Max();
result.Add(a);
list.Remove(a);
}
}
return result;
}
public int GetSumOfAllIntegers(object[] data)
{
int sum = 0;
for (int i = 0; i < data.Length; i++)
{
if (data[i] is int)
{
sum = sum + (Convert.ToInt32(data[i]));
}
}
return sum;
}
}
}