Calculates the median of the values. If there is an even number of items, the average of the middle ones is returned.

Type signature

(xs?: number[]) => number | undefined

Examples

median([-5, 3, 2, 29, 43]);
// ⇒ 3
Try in REPL

Questions

  • How to compute a median of an array?

TypeScript sourceJavaScript source