-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20eb6f6
commit 13339c7
Showing
1 changed file
with
31 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,42 @@ | ||
--- | ||
title: similarity | ||
description: Compare two strings and return a similarity score | ||
description: Calculate the similarity between two strings using the Levenshtein distance algorithm | ||
--- | ||
|
||
### Usage | ||
|
||
Does a thing. Returns a value. | ||
The `similarity` function computes the Levenshtein distance between two input strings. This distance represents the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other. | ||
|
||
```ts | ||
This function is useful for various applications, including: | ||
|
||
- Spell checking and autocorrect features | ||
- Fuzzy string matching | ||
- DNA sequence analysis | ||
- Plagiarism detection | ||
|
||
The function is case-sensitive and treats whitespace as significant characters. The order of the input strings doesn't affect the result, as the Levenshtein distance is symmetric. | ||
|
||
```typescript | ||
import * as _ from 'radashi' | ||
|
||
_.similarity() | ||
// Identical strings | ||
_.similarity('hello', 'hello') // => 0 | ||
|
||
// One character difference | ||
_.similarity('kitten', 'sitten') // => 1 | ||
|
||
// Multiple differences | ||
_.similarity('saturday', 'sunday') // => 3 | ||
|
||
// Case sensitivity | ||
_.similarity('foo', 'FOO') // => 3 | ||
|
||
// Whitespace significance | ||
_.similarity('bar ', 'bar') // => 1 | ||
|
||
// Argument order doesn't matter | ||
_.similarity('abc', 'cba') // => 2 | ||
_.similarity('cba', 'abc') // => 2 | ||
``` | ||
|
||
https://en.wikipedia.org/wiki/Levenshtein_distance | ||
The function returns a `number` representing the Levenshtein distance between the two input strings. A lower number indicates higher similarity, with 0 meaning the strings are identical. |