Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

std/text/mod.ts>wordSimilaritySort

The Deno Standard Library
Latest
function wordSimilaritySort
import { wordSimilaritySort } from "https://deno.land/std@0.224.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.224.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