Calculate

Calculate

  • Docs
  • Help
  • Blog

›Statistics

Getting Started

  • Installation
  • Updating Calculate

Math

  • Sum
  • Difference
  • Product
  • Quotient
  • Remainder
  • Power
  • Square
  • Cube
  • Factorial

Statistics

  • Mean
  • Median
  • Mode
  • Range

Median

Gets the median of given numbers or the middle number in a sorted list of numbers.

Syntax

median(a: number, b: number, ...args): number

Parameters

a: number - First given number.

b: number - Second given number.

...args: number[] - The rest of the given numbers

Can be given an infinite number of parameters.

Returns

number - The resulting median.

Error

Throws an error if the length of arguments is less than 2.

Import

import { median } from '@princedev/calculate';

Examples

Basic usage with even length of numbers.

const result = median(21, 4, 8, 6);

result would be 7

Getting the median with an odd length of numbers.

const result = median(21, 4, 8, 6, 12);

result would be 8

If you're using an array, you can use the spread operator like this

const result = median(...[21, 4, 8, 6, 12]);

result would be 8

Last updated on 5/6/2020 by Prince Neil Cedrick Castro
← MeanMode →
  • Syntax
    • Parameters
    • Returns
    • Error
  • Import
  • Examples
Calculate
Docs
Getting StartedGuides
Package
NPMGitHubStar
More
HelpBlog
aws.cedi@gmail.com
Copyright © 2020 Calculate