deno.land / x / denon@2.5.0 / src / closest.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Copyright 2020-2021 the denosaurs team. All rights reserved. MIT license.
import { levenshtein } from "../deps.ts";
/** Returns the closest string in the array */export function closest(word: string, words: string[]): string | undefined { if (words.length === 0) return;
const dist = words.map((w) => levenshtein(word, w)); const index = dist.indexOf(Math.min(...dist));
return words[index];}
denon

Version Info

Tagged at
2 years ago