# uniq

> Removes duplicates from a sorted array in place

Latest version **1.0.1** (published 2014-05-25) · MIT license · 0 weekly downloads

> **Better alternative:** Use [...new Set(arr)] — Consider using a lighter alternative

## Install

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

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2014-05-25 |
| First published | 2013-03-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/uniq) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 83 |
| Author | Mikola Lysenko |
| Maintainers | mikolalysenko |
| Keywords | array, duplicate, unique, uniq, remove, sort, in, place, no, copy |

## Links

- npm: https://www.npmjs.com/package/uniq
- Repository: https://github.com/mikolalysenko/uniq
- Issues: https://github.com/mikolalysenko/uniq/issues
- npm.io page: https://npm.io/package/uniq

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@pandacss/eslint-plugin](https://npm.io/package/@pandacss/eslint-plugin.md) — 18.7K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2014-05-25
- 1.0.0 — 2014-04-29
- 0.0.2 — 2013-03-31
- 0.0.0 — 2013-03-24

## README

uniq
====
Removes all duplicates from an array in place.

Usage
=====
First install using npm:

    npm install uniq
    
Then use it as follows:

```javascript

var arr = [1, 1, 2, 2, 3, 5]

require("uniq")(arr)
console.log(arr)

//Prints:
//
//  1,2,3,5
//
```

## `require("uniq")(array[, compare, sorted])`
Removes all duplicates from a sorted array in place.

* `array` is the array to remove items from
* `compare` is an optional comparison function that returns 0 when two items are equal, and something non-zero when they are different.  If unspecified, then the default equals will be used.
* `sorted` if true, then assume array is already sorted

**Returns:** A reference to `array`

**Time Complexity:** `O(array.length * log(arra.length))` or `O(array.length)` if `sorted`


## Why use this instead of underscore.uniq[ue]?
A few reasons:

* This library updates the array in place without making an extra copy (and so it is faster for large arrays)
* It also accepts a custom comparison function so you can remove duplicates from arrays containing object
* It is more modular in the sense that it doesn't come with a bazillion other utility grab bag functions.

# Credits
(c) 2013 Mikola Lysenko. MIT License

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