Function wordSimilaritySort
- word
Similarity (givenWord, possibleWords, options?): string[]Sort Parameters
- givenWord: string
The string to measure distance against.
- possibleWords: readonly string[]
The string-array that will be sorted. This array will not be mutated, but the sorted copy will be returned.
Optionaloptions: WordSimilaritySortOptionsOptions for the sort.
Returns string[]
A sorted copy of
possibleWords.Example: Basic usage
import { wordSimilaritySort } from "@std/text/word-similarity-sort";
import { assertEquals } from "@std/assert";
const possibleWords = ["length", "size", "blah", "help"];
const suggestions = wordSimilaritySort("hep", possibleWords);
assertEquals(suggestions, ["help", "size", "blah", "length"]);Example: Case-sensitive sorting
import { wordSimilaritySort } from "@std/text/word-similarity-sort";
import { assertEquals } from "@std/assert";
const possibleWords = ["length", "Size", "blah", "HELP"];
const suggestions = wordSimilaritySort("hep", possibleWords, { caseSensitive: true });
assertEquals(suggestions, ["Size", "blah", "HELP", "length"]);- givenWord: string
Sorts a string-array by similarity to a given string.
By default, calculates the distance between words using the Levenshtein distance.