Skip to content

Commit

Permalink
update Int Array Extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-Maes committed Dec 13, 2023
1 parent d9200da commit e08b9ba
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 21 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,8 @@ Or just copy whatever you need from this repository :)
|-----------------------------------|---------------------------------------------------|
|`AverageIgnoringZero`| Calculates the average of the elements in the array, ignoring zero values.|
|`FindPrimeNumbers`| Filters the array to include only prime numbers.|
|`GCD`| Calculates the Greatest Common Divisor of all array elements.|
|`IsMonotonicallyIncreasing`| Checks if the array's elements are in a strictly increasing order. |
|`IsMonotonicallyDecreasing`| Checks if the array's elements are in a strictly decreasing order.|
|`LCM`| Finds the Least Common Multiple of all array elements.|
|`MultiplyAll`| Multiplies all elements in the array and returns the product.|
|`Mode`| Finds the most frequently occurring number(s) in the array.|
|`Percentile`| Finds the percentile value in the array.|
Expand Down
2 changes: 1 addition & 1 deletion src/ArrayExtensions/ArrayExtensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageProjectUrl>https://www.github.com/Tim-Maes/ArrayExtensions</PackageProjectUrl>
<RepositoryUrl>https://www.github.com/Tim-Maes/ArrayExtensions</RepositoryUrl>
<PackageTags>array, extensions</PackageTags>
<Version>1.2.6</Version>
<Version>1.2.7</Version>
<EnablePackageValidation>true</EnablePackageValidation>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
18 changes: 0 additions & 18 deletions src/ArrayExtensions/IntArrayExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,6 @@ public static bool IsMonotonicallyDecreasing(this int[] arr)
public static IEnumerable<int> Mode(this int[] arr)
=> arr.GroupBy(n => n).OrderByDescending(g => g.Count()).Select(g => g.Key);

/// <summary>
/// Calculates the Greatest Common Divisor of all array elements.
/// </summary>
/// <param name="arr">The array to process.</param>
/// <returns>The greatest common divisor of the array elements.</returns>
public static int GCD(this int[] arr)
=> arr.Aggregate((x, y) => GCD(x, y));
private static int GCD(int a, int b)
=> b == 0 ? a : GCD(b, a % b);

/// <summary>
/// Finds the Least Common Multiple of all array elements.
/// </summary>
/// <param name="arr">The array to process.</param>
/// <returns>The least common multiple of the array elements.</returns>
public static long LCM(this int[] arr)
=> arr.Aggregate(1L, (a, b) => a * b / GCD(a, b));

/// <summary>
/// Finds the percentile value in the array.
/// </summary>
Expand Down

0 comments on commit e08b9ba

Please sign in to comment.