# list-diff-hash

> Diff two lists/strings in O(n*m) with hash function

Latest version **1.2.0** (published 2018-03-17) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install list-diff-hash
pnpm add list-diff-hash
yarn add list-diff-hash
bun add list-diff-hash
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2018-03-17 |
| First published | 2018-03-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 14.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | kapouer |
| Keywords | diff, list diff |

## Links

- npm: https://www.npmjs.com/package/list-diff-hash
- Repository: https://github.com/kapouer/list-diff-hash
- Issues: https://github.com/kapouer/list-diff-hash/issues
- npm.io page: https://npm.io/package/list-diff-hash

## Dependencies (1)

- [standard](https://npm.io/package/standard.md) ^11.0.1

## Recent versions

- 1.2.0 (latest) — 2018-03-17
- 1.1.0 — 2018-03-17
- 1.0.0 — 2018-03-17

## README

list-diff-hash
==============

Fork of [list-diff.js](https://github.com/toplan/list-diff),
with support for a hash function.

## Introduction

Diff two lists/strings in time O(n*m).

The algorithm finding the minimal amount of moves(patches) is [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance).

## Install

```
npm install list-diff-hash --save
```

## Usage

```javascript
var Diff = require("list-diff-hash")
var oldList = [{id: "a"}, {id: "b"}, {id: "c"}, {id: "d"}, {id: "e"}]
var newList = [{id: "c"}, {id: "a"}, {id: "b"}, {id: "e"}, {id: "f"}]

var patches = Diff(oldList, newList, "id")

patches.forEach(function (patch) {
  if (patch.type === Diff.DELETION) {
    oldList.splice(patch.index, 1)
  } else if (patch.type === Diff.INSERTION) {
    oldList.splice(patch.index, 0, patch.item)
  } else if (patch.type === Diff.SUBSTITUTION) {
    oldList.splice(patch.index, 1, patch.item)
  }
})

// now `oldList` is equal to `newList`
// [{id: "c"}, {id: "a"}, {id: "b"}, {id: "e"}, {id: "f"}]
console.log(oldList)
```

With a hash function:

```
var patches = Diff(oldList, newList, function(item) {
	return item.id
})
```

If `list-diff-hash.js` is added to a web page, it is exposed as `window.ListDiff`.

## License 
MIT

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