Maths
median

Calculates the median value of the given array.

Median: The middle number; found by ordering all data points and picking out the one in the middle (or if there are two middle numbers, taking the mean of those two numbers).

Syntax

import { median } from '@opentf/std';
 
median(
  arr: number[] = [],
  cb?: (val: number, index: number) => number
): number

Examples

median([]) //=> NaN
 
median([1]) //=> 1
 
median([4, 1, 7]) //=> 1
 
median([4, 2, 8]) //=> 2
 
median([1, 4, 2, 5, 0]) //=> 2
 
median([10, 20, 40, 50]) //=> 30

Try