https://github.com/alordash/damerau-levenshtein
My realization of Damerau-Levenshtein distance algorithm.
https://github.com/alordash/damerau-levenshtein
Last synced: about 1 month ago
JSON representation
My realization of Damerau-Levenshtein distance algorithm.
- Host: GitHub
- URL: https://github.com/alordash/damerau-levenshtein
- Owner: alordash
- License: mit
- Created: 2020-08-09T09:28:49.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-07-02T10:57:49.000Z (almost 4 years ago)
- Last Synced: 2025-03-15T08:48:51.409Z (2 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@alordash/damerau-levenshtein
- Size: 34.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# @alordash/damerau-levenshtein
```
$ npm i @alordash/damerau-levenshtein
```# Levenshtein algorithm
My realization of [Damerau-Levenshtein distance](https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance) algorithm.
# Usage
```javascript
const { distance, closest } = require('@alordash/damerau-levenshtein')// Print Damerau-Levenshtein distance between "better" and "bteetr"
console.log(distance("better", "bteetr"));
//=> 2// Select the most similar string to "park" from string list.
let value = closest("park", ["luck", "duck", "apkr"]);// Result:
console.log(value.closest_string);
//=> "apkr"console.log(value.distance);
//=> 2
```# Features
You can also create calculation object using **DamerauLevenshtein** class:
```javascript
const { DamerauLevenshtein } = require("@alordash/levenshtein");// Calculate Damerau-Levenshtein distance between "entity" and "idenitty"
let object = new DamerauLevenshtein("entity", "idenitty");// Print Damerau-Levenshtein distance between "entity" and "idenitty"
console.log(object.valueOf(), object.distance);
//=> 3 3// Change strings in object to "first" and "wrist" and calculate Damerau-Levenshtein distance between them
object.strings = ["first", "wrist"];// Print Damerau-Levenshtein distance between "first" and "wrist"
console.log(object.distance);
//=> 2// Print calculation matrix
console.log(object.toString());
//=>
// | | w | r | i | s | t
//—————+–––+–––+–––+–––+–––+–––
// | 0 | 1 | 2 | 3 | 4 | 5
//—————+–––+–––+–––+–––+–––+–––
// f | 1 | 1 | 2 | 3 | 4 | 5
//—————+–––+–––+–––+–––+–––+–––
// i | 2 | 2 | 2 | 2 | 3 | 4
//—————+–––+–––+–––+–––+–––+–––
// r | 3 | 3 | 2 | 2 | 3 | 4
//—————+–––+–––+–––+–––+–––+–––
// s | 4 | 4 | 3 | 3 | 2 | 3
//—————+–––+–––+–––+–––+–––+–––
// t | 5 | 5 | 4 | 4 | 3 | 2
//—————+–––+–––+–––+–––+–––+–––
```