-
Notifications
You must be signed in to change notification settings - Fork 1
/
ListExtensions.cs
53 lines (50 loc) · 1.46 KB
/
ListExtensions.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
using System;
using System.Collections.Generic;
using System.Linq;
namespace ReeCode
{
public static class ListExtensions
{
/// <summary>
/// Checks if all values in the list are factors of a number
/// </summary>
/// <returns>True / False</returns>
public static bool AreAllFactorsOf(this List<int> inputList, int x)
{
foreach (int num in inputList)
{
if (x % num != 0)
{
return false;
}
}
return true;
}
/// <summary>
/// Checks if a List contains any letters from another List
/// </summary>
/// <returns>True / False</returns>
public static bool ContainsAnyLettersFrom(this List<char> inputList, List<char> checkList)
{
if (inputList.Intersect(checkList).Any())
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// Finds the Median value of a list
/// </summary>
/// <param name="inputList"></param>
/// <returns>The Median value</returns>
public static double Median(this List<double> inputList)
{
double[] xs = inputList.ToArray();
Array.Sort(xs);
return xs[xs.Length / 2];
}
}
}