The median()
function returns the median of its arguments. It accepts numbers, lists of numbers, or a combination of the two.
median(number, ...)
median([number, ...])
median([number], number)
Code language: JavaScript (javascript)
If using dot notation, the numbers must all be part of the same list:
[number, ...].median()
Code language: JavaScript (javascript)
The median of a list or group of numbers is the value that separates the higher half of the values from the lower half, after organizing the list in ascending order.
If the list has an odd number of values, the middle value is the median. If it has an even number of values, the median is the sum of the two middle values divided by 2.
Example Formulas
median(15, 35, 70) /* Output: 35 */
[30, 60, 110, 75].mean() /* Output: 67.5 (60 and 75 are the middle values */
mean(2, 5, [4, 30, 13], 9) /* Output: 7 (5 and 9 are the middle values) */
Code language: JavaScript (javascript)