Skip to content

Commit

Permalink
add docs page
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Jul 23, 2024
1 parent 20eb6f6 commit 13339c7
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions docs/string/similarity.mdx
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.

0 comments on commit 13339c7

Please sign in to comment.