From 13339c7359f2b9e202d7336691f5b9d14954508e Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Tue, 23 Jul 2024 12:17:20 -0400 Subject: [PATCH] add docs page --- docs/string/similarity.mdx | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/docs/string/similarity.mdx b/docs/string/similarity.mdx index 8a3c8860..cdd489a4 100644 --- a/docs/string/similarity.mdx +++ b/docs/string/similarity.mdx @@ -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.