1
var t0 = [  "site",        "how", "social",     "create", "membership"],
    t1 = [ "forum",       "site", "social", "membership", "networking"],
    t2 = ["social",    "network", "create",        "how",       "free"],
    t3 = ["social", "membership",   "site",    "website",       "make"] ;

    function levenshteinDistance (a, b) {
        if (!a.length) return b.length;
        if (!b.length) return a.length;
        return Math.min(
            levenshteinDistance(a.slice(1), b) + 1,
            levenshteinDistance(b.slice(1), a) + 1,
            levenshteinDistance(a.slice(1), b.slice(1)) + (a[0] !== b[0] ? 1 : 0)
        );
    }
    console.log(levenshteinDistance (t0, t1));
    console.log(levenshteinDistance (t0, t2));

    .linkDistance(levenshteinDistance (t0, t1))

我需要一个根据 Levenshtein 距离函数之前给出的数据提供动态距离的函数。我想根据我的功能创建动态链接距离。我将 Levenshtein 距离函数放在同一页面上。我是新来的,如果我犯了错误,请确认我。如果你需要我会在这里回答你的问题。

4

0 回答 0