# quickselect

> A tiny and fast selection algorithm in JavaScript.

Latest version **3.0.0** (published 2024-07-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install quickselect
pnpm add quickselect
yarn add quickselect
bun add quickselect
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2024-07-03 |
| First published | 2016-02-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 96 |
| Author | Vladimir Agafonkin |
| Maintainers | mourner |
| Keywords | selection, algorithm, quickselect, sort, partial, floyd, rivest |

## Links

- npm: https://www.npmjs.com/package/quickselect
- Repository: https://github.com/mourner/quickselect
- Homepage: https://github.com/mourner/quickselect#readme
- Issues: https://github.com/mourner/quickselect/issues
- npm.io page: https://npm.io/package/quickselect

## Recent versions

- 3.0.0 (latest) — 2024-07-03
- 2.0.0 — 2018-04-04
- 1.1.1 — 2018-04-04
- 1.1.0 — 2018-04-03
- 1.0.1 — 2017-12-21
- 1.0.0 — 2016-02-17

## README

## quickselect

A tiny and fast [selection algorithm](https://en.wikipedia.org/wiki/Selection_algorithm) in JavaScript
(specifically, [Floyd-Rivest selection](https://en.wikipedia.org/wiki/Floyd%E2%80%93Rivest_algorithm)).

```js
quickselect(array, k[, left, right, compareFn]);
```

Rearranges items so that all items in the `[left, k]` are the smallest.
The `k`-th element will have the `(k - left + 1)`-th smallest value in `[left, right]`.

- `array`: the array to partially sort (in place)
- `k`: middle index for partial sorting (as defined above)
- `left`: left index of the range to sort (`0` by default)
- `right`: right index (last index of the array by default)
- `compareFn`: compare function

Example:

```js
const arr = [65, 28, 59, 33, 21, 56, 22, 95, 50, 12, 90, 53, 28, 77, 39];

quickselect(arr, 8);

// arr is [39, 28, 28, 33, 21, 12, 22, 50, 53, 56, 59, 65, 90, 77, 95]
//                                         ^^ middle index
```

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