Skip to main content
Go to Latest
function wordSimilaritySort
import { wordSimilaritySort } from "https://deno.land/std@0.221.0/text/mod.ts";

Sorts a string-array by similarity to a given string

Examples

Example 1

import { wordSimilaritySort } from "https://deno.land/std@0.221.0/text/word_similarity_sort.ts";

const possibleWords = ["length", "size", "blah", "help"];

// case-insensitive by default
const suggestions = wordSimilaritySort("hep", possibleWords).join(", ");

// force case sensitive
wordSimilaritySort("hep", possibleWords, { caseSensitive: true });

Parameters

givenWord: string
  • The string to measure distance against
possibleWords: string[]
  • The string-array that will be sorted
optional
options: { caseSensitive?: boolean; }
  • Flag indicating whether the distance should include case. Default is false.

Returns

string[]

A sorted copy of possibleWords