Skip to content
This repository was archived by the owner on Nov 14, 2022. It is now read-only.

Commit 1474cdc

Browse files
committed
- not doing double conversion on array index
1 parent aceca06 commit 1474cdc

File tree

1 file changed

+4
-3
lines changed
  • ClosedXML/Excel/CalcEngine/Functions

1 file changed

+4
-3
lines changed

ClosedXML/Excel/CalcEngine/Functions/Tally.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,18 @@ public double Median()
7676

7777
if (nums.Length == 0) throw new ApplicationException("No values");
7878

79-
bool hasEvenCount = nums.Length % 2 == 0;
79+
var hasEvenCount = nums.Length % 2 == 0;
80+
8081
if (hasEvenCount)
8182
{
82-
int numElementsToSkip = (nums.Length / 2) - 1;
83+
var numElementsToSkip = (nums.Length / 2) - 1;
8384

8485
return nums.Skip(numElementsToSkip)
8586
.Take(2)
8687
.Average();
8788
}
8889

89-
int medianIndex = (int)Math.Floor(nums.Length / 2d);
90+
var medianIndex = (nums.Length - 1) / 2;
9091

9192
return nums[medianIndex];
9293
}

0 commit comments

Comments
 (0)