Files
freeCodeCamp/curriculum/challenges/chinese/08-coding-interview-prep/rosetta-code/jaro-distance.chinese.md
Kristofer Koishigawa b3213fc892 fix(i18n): chinese test suite (#38220)
* fix: Chinese test suite

Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working.

* fix: ran script, updated testStrings and solutions
2020-03-03 18:49:47 +05:30

3.2 KiB
Raw Blame History

title, id, challengeType, videoUrl, localeTitle
title id challengeType videoUrl localeTitle
Jaro distance 5a23c84252665b21eecc7ec2 5 Jaro距离

Description

Jaro距离是两个弦之间相似性的度量。两个弦的Jaro距离越高弦越相似。对得分进行归一化使得0等于没有相似性, 1等于完全匹配。定义两个给定字符串\s_1 \)和\s_2 \的Jaro距离\d_j \)是\ begin {align} d_j = \ begin {cases} 0 && \ text {if} m = 0 \\\ \ {\ frac {1} {3}} \ left{\ frac {m} {| s_ {1} |}} + {\ frac {m} {| s_ {2} |}} + {\ frac { mt} {m}} \ right&& \ text {otherwise} \ end {cases} \ end {align}其中:
  • \m \)是匹配字符的数量;
  • \t \)是换位次数的一半。
分别来自\s_1 \)和\s_2 \)的两个字符只有在相同且不远于\\ left \ lfloor \ frac {\ max| s_1 || s_2 |}时才被认为是匹配的 {2} \右\ rfloor-1 \)。将\s_1 \)的每个字符与\s_2 \中的所有匹配字符进行比较。匹配但不同的序列顺序字符除以2的数量定义了转置的数量。 示例给定字符串\s_1 \ DWAYNE和\s_2 \ DUANE我们发现:
  • \m = 4 \
  • \| s_1 | = 6 \
  • \| s_2 | = 5 \
  • \t = 0 \
我们发现Jaro得分为\d_j = \ frac {1} {3} \ left\ frac {4} {6} + \ frac {4} {5} + \ frac {4-0} {4} \ right= 0.822 \。编写一个函数a它接受两个字符串作为参数并返回相关的Jaro距离。

Instructions

Tests

tests:
  - text: <code>jaro</code>应该是一个功能。
    testString: assert(typeof jaro=='function');
  - text: <code>jaro(""+tests[0][0]+"",""+tests[0][1]+"")</code>应返回一个数字。
    testString: assert(typeof jaro('MARTHA', 'MARHTA')=='number');
  - text: <code>jaro(""+tests[0][0]+"",""+tests[0][1]+"")</code>应该返回<code>"+results[0]+"</code> 。
    testString: assert.equal(jaro('MARTHA', 'MARHTA'), 0.9444444444444445);
  - text: <code>jaro(""+tests[1][0]+"",""+tests[1][1]+"")</code>应返回<code>"+results[1]+"</code> 。
    testString: assert.equal(jaro('DIXON', 'DICKSONX'), 0.7666666666666666);
  - text: <code>jaro(""+tests[2][0]+"",""+tests[2][1]+"")</code>应返回<code>"+results[2]+"</code> 。
    testString: assert.equal(jaro('JELLYFISH', 'SMELLYFISH'), 0.8962962962962964);
  - text: <code>jaro(""+tests[3][0]+"",""+tests[3][1]+"")</code>应返回<code>"+results[3]+"</code> 。
    testString: assert.equal(jaro('HELLOS', 'CHELLO'), 0.888888888888889);
  - text: <code>jaro(""+tests[4][0]+"",""+tests[4][1]+"")</code>应该返回<code>"+results[4]+"</code> 。
    testString: assert.equal(jaro('ABCD', 'BCDA'), 0.8333333333333334);

Challenge Seed

function jaro (s, t) {
  // Good luck!
}

After Test

console.info('after the test');

Solution

// solution required