# ml-array-median

> Get the median value in an array

Latest version **2.0.0** (published 2026-04-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install ml-array-median
pnpm add ml-array-median
yarn add ml-array-median
bun add ml-array-median
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2026-04-14 |
| First published | 2017-07-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 2 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | Jefferson Hernández |
| Maintainers | stropitek, targos, lpatiny, mljs-bot, maasencioh |

## Links

- npm: https://www.npmjs.com/package/ml-array-median
- Repository: https://github.com/mljs/array
- Homepage: https://github.com/mljs/array/tree/master/packages/array-median#readme
- Issues: https://github.com/mljs/array/issues
- npm.io page: https://npm.io/package/ml-array-median

## Dependencies (2)

- [is-any-array](https://npm.io/package/is-any-array.md) ^3.0.0
- [median-quickselect](https://npm.io/package/median-quickselect.md) ^1.0.1

## Recent versions

- 2.0.0 (latest) — 2026-04-14
- 1.1.6 — 2022-01-21
- 1.1.5 — 2021-03-24
- 1.1.4 — 2020-10-07
- 1.1.3 — 2020-04-02
- 1.1.2 — 2019-08-30
- 1.1.1 — 2018-11-09
- 1.1.0 — 2018-10-26
- 1.0.2 — 2018-08-03
- 1.0.1 — 2017-07-21
- 1.0.0 — 2017-07-11

## README

# array-median

[![NPM version][npm-image]][npm-url]
[![npm download][download-image]][download-url]

Get the median value in an array, this median use the [Floyd-Rivest algorithm](https://en.wikipedia.org/wiki/Floyd%E2%80%93Rivest_algorithm).

Thanks to [mad-gooze](https://github.com/mad-gooze) for his median-quickselect [lib](https://github.com/mad-gooze/median-quickselect).

Some benchmarks [here](https://jsperf.com/median-inplace/1).

## Installation

`$ npm install --save ml-array-median`

## Usage

```js
import median from 'ml-array-median';

const result = median([1, 5, 3, 2, 4]);
// 3
```

## License

[MIT](./LICENSE)

[npm-image]: https://img.shields.io/npm/v/ml-array-median.svg?style=flat-square
[npm-url]: https://npmjs.org/package/ml-array-median
[download-image]: https://img.shields.io/npm/dm/ml-array-median.svg?style=flat-square
[download-url]: https://npmjs.org/package/ml-array-median

---
_Source: https://npm.io/package/ml-array-median · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
