forked from suncoast-devs/net-iteration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIterations.cs
171 lines (139 loc) · 5.7 KB
/
Iterations.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
using System;
using System.Collections.Generic;
using System.Linq;
using DotnetIteration.Models;
namespace DotnetIteration
{
public static class Iteration
{
/*
Welcome to Interation
In each method below you will see instructions that detail the requirements
the method must implement to make the test pass.
To start on a method comment out, or remove, the line
`throw new System.NotImplementedException();`
As you write and save your code, you can look in your terminal where you
ran `dotnet watch test` to see if your code is working. The tests
continuously check your work each time you save. If a test is failing
you have not yet completed that method. Once you finish a method and have
it correct, the test will tell you how the next method is working.
*/
//
// 1) Complete the method named `yelling` that takes a list of
// words as an argument and returns a new list with all
// the words forced to uppercase.
//
public static IEnumerable<string> Yelling(List<string> words)
{
var upperCase = words.ConvertAll(value => value.ToUpper());
return upperCase;
//throw new System.NotImplementedException();
}
//
// 2) Complete the method named `Double` that takes a list of
// numbers as an argument and returns a new list with all
// the numbers multiplied by 2.
//
public static IEnumerable<int> Double(List<int> numbers)
{
var newDouble = numbers.Select(value => value * 2);
return newDouble;
//throw new System.NotImplementedException();
}
//
// 3) Complete the method `StringyIndexes` that takes a list of
// strings as an argument and returns a new list with each
// string suffixed with " is at index X" where X is the index
// of the element.
//
public static IEnumerable<string> StringyIndexes(List<string> words)
{
var stingyNewIndex = words.Select((word, index) => $"{word} is at index {index}");
return stingyNewIndex;
//throw new System.NotImplementedException();
}
//
// 4) Complete the method OnlyTheEvenSurvive that accepts a list of
// numbers and returns only the elements that are even.
//
public static IEnumerable<int> OnlyTheEvenSurvive(List<int> numbers)
{
var theEvens = numbers.Where(value => value % 2 == 0);
return theEvens;
//throw new System.NotImplementedException();
}
//
// 5) Complete the method OnlyTheEvenIndexedSurvive that accepts a
// list of numbers and returns only the elements at indexes that
// are even.
//
public static IEnumerable<int> OnlyTheEvenIndexedSurvive(List<int> numbers)
{
var evenIndex = numbers.Where((numbers, index) => index % 2 == 0);
return evenIndex;
//throw new System.NotImplementedException();
}
//
// 6) Complete the method BestMoviesOfTheYear that accepts a list of
// movie objects AND a year and returns the names of movies that are
// from that year AND have a score more than 90.
//
// A movie object looks like this:
//
// new Movie() {
// Name: "Get Out",
// Year: "2017",
// Score: 99
// }
//
public static IEnumerable<string> BestMovieOfTheYear(List<Movie> movies, int yearToMatch)
{
var bestMovieAbove = movies.Where(value => ((value.Year == yearToMatch) && (value.Score > 90))).Select(value => value.Name);
return bestMovieAbove;
//throw new System.NotImplementedException();
}
//
// 7) Complete the method EveryoneIsOdd that accepts a list of
// numbers and returns true if every element of the list is odd.
//
public static bool EveryoneIsOdd(List<int> numbers)
{
var trueOdd = numbers.All(value => 2 != 0);
return trueOdd;
//throw new System.NotImplementedException();
}
//
// 8) Complete the method FindTheNeedle that accepts a list of
// strings and returns the one string that contains the word
// `needle`.
//
public static string FindTheNeedle(List<string> sentences)
{
var findTheWord = sentences.First(value => value.Contains("needle"));
return findTheWord;
//throw new System.NotImplementedException();
}
//
// 9) Complete the method FindTheNeedleIndex that accepts a list of
// strings and returns the index of the string that contains
// the word `needle` inside.
//
public static int FindTheNeedleIndex(List<string> sentences)
{
var findIndexNeedle = sentences.FindIndex(value => value.Contains("needle"));
return findIndexNeedle;
//throw new System.NotImplementedException();
}
//
// 10) Complete the method SomeoneToLove that accepts a list of
// strings and returns true if at least one string is exactly
// four characters long.
//
public static bool SomeoneToLove(List<string> words)
{
var fourCharactersLong = words.Any(value => value.Length == 4);
return fourCharactersLong;
//throw new System.NotImplementedException();
}
}
}