Skip to content

Commit

Permalink
Change var name in median calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Redm4x committed Apr 11, 2024
1 parent 479d608 commit de7ddc5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions api/src/utils/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export function median(values: number[]): number {
throw new Error("Input array is empty");
}

values = [...values].sort((a, b) => a - b);
const sortedValues = [...values].sort((a, b) => a - b);

const half = Math.floor(values.length / 2);
const half = Math.floor(sortedValues.length / 2);

return values.length % 2 === 0 ? (values[half - 1] + values[half]) / 2 : values[half];
return sortedValues.length % 2 === 0 ? (sortedValues[half - 1] + sortedValues[half]) / 2 : sortedValues[half];
}

export function average(values: number[]): number {
Expand Down

0 comments on commit de7ddc5

Please sign in to comment.