Feat: add new Markdown parser (#39800)

and change all the challenges to new `md` format.
This commit is contained in:
Oliver Eyton-Williams
2020-11-27 19:02:05 +01:00
committed by GitHub
parent a07f84c8ec
commit 0bd52f8bd1
2580 changed files with 113436 additions and 111979 deletions

View File

@ -1,67 +1,95 @@
---
title: Jaro distance
id: 5a23c84252665b21eecc7ec2
title: Jaro distance
challengeType: 5
forumTopicId: 302292
---
## Description
<section id='description'>
The Jaro distance is a measure of similarity between two strings. The higher the Jaro distance for two strings is, the more similar the strings are. The score is normalized such that <code>0</code> equates to no similarity and <code>1</code> is an exact match.
<strong>Definition</strong>
The Jaro distance \( d_j \) of two given strings \(s_1\) and \(s_2\) is
\begin{align}d_j = \begin{cases}0&amp; & \text{if }m=0 \\\\{\frac {1}{3}}\left({\frac {m}{|s_{1}|}}+{\frac {m}{|s_{2}|}}+{\frac {m-t}{m}}\right)&amp; & \text{otherwise}\end{cases}\end{align}
# --description--
The Jaro distance is a measure of similarity between two strings. The higher the Jaro distance for two strings is, the more similar the strings are. The score is normalized such that `0` equates to no similarity and `1` is an exact match.
**Definition**
The Jaro distance \\( d_j \\) of two given strings \\(s_1\\) and \\(s_2\\) is
\\begin{align}d_j = \\begin{cases}0& & \\text{if }m=0 \\\\\\\\{\\frac {1}{3}}\\left({\\frac {m}{|s\_{1}|}}+{\\frac {m}{|s\_{2}|}}+{\\frac {m-t}{m}}\\right)& & \\text{otherwise}\\end{cases}\\end{align}
Where:
<ul>
<li>\(m\) is the number of <i>matching characters</i>;</li>
<li> \(t\) is half the number of <i>transpositions</i>.</li>
</uL>
Two characters from \(s_1\) and \(s_2\) respectively, are considered <i>matching</i> only if they are the same and not farther than \(\left\lfloor\frac{\max(|s_1|,|s_2|)}{2}\right\rfloor-1\).
Each character of \(s_1\) is compared with all its matching characters in \(s_2\) . The number of matching (but different sequence order) characters divided by 2 defines the number of <i>transpositions</i>.
<strong>Example</strong>
Given the strings \(s_1\) <i>DWAYNE</i> and \(s_2\) <i>DUANE</i> we find:
</ul>
Two characters from \\(s_1\\) and \\(s_2\\) respectively, are considered *matching* only if they are the same and not farther than \\(\\left\\lfloor\\frac{\\max(|s_1|,|s_2|)}{2}\\right\\rfloor-1\\).
Each character of \\(s_1\\) is compared with all its matching characters in \\(s_2\\) . The number of matching (but different sequence order) characters divided by 2 defines the number of *transpositions*.
**Example**
Given the strings \\(s_1\\) *DWAYNE* and \\(s_2\\) *DUANE* we find:
<ul>
<li>\(m = 4\)</li>
<li>\(|s_1| = 6\)</li>
<li>\(|s_2| = 5\)</li>
<li>\(t = 0\)</li>
</ul>
We find a Jaro score of: \(d_j = \frac{1}{3}\left(\frac{4}{6} + \frac{4}{5} + \frac{4-0}{4}\right) = 0.822\).
</section>
## Instructions
<section id='instructions'>
We find a Jaro score of: \\(d_j = \\frac{1}{3}\\left(\\frac{4}{6} + \\frac{4}{5} + \\frac{4-0}{4}\\right) = 0.822\\).
# --instructions--
Write a function a that takes two strings as parameters and returns the associated Jaro distance.
</section>
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: <code>jaro</code> should be a function.
testString: assert(typeof jaro=='function');
- text: <code>jaro("MARTHA", "MARHTA")</code> should return a number.
testString: assert(typeof jaro('MARTHA', 'MARHTA')=='number');
- text: <code>jaro("MARTHA", "MARHTA")</code> should return <code>0.9444444444444445</code>.
testString: assert.equal(jaro('MARTHA', 'MARHTA'), 0.9444444444444445);
- text: <code>jaro("DIXON", "DICKSONX")</code> should return <code>0.7666666666666666</code>.
testString: assert.equal(jaro('DIXON', 'DICKSONX'), 0.7666666666666666);
- text: <code>jaro("JELLYFISH", "SMELLYFISH")</code> should return <code>0.8962962962962964</code>.
testString: assert.equal(jaro('JELLYFISH', 'SMELLYFISH'), 0.8962962962962964);
- text: <code>jaro("HELLOS", "CHELLO")</code> should return <code>0.888888888888889</code>.
testString: assert.equal(jaro('HELLOS', 'CHELLO'), 0.888888888888889);
- text: <code>jaro("ABCD", "BCDA")</code> should return <code>0.8333333333333334</code>.
testString: assert.equal(jaro('ABCD', 'BCDA'), 0.8333333333333334);
`jaro` should be a function.
```js
assert(typeof jaro == 'function');
```
</section>
`jaro("MARTHA", "MARHTA")` should return a number.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(typeof jaro('MARTHA', 'MARHTA') == 'number');
```
<div id='js-seed'>
`jaro("MARTHA", "MARHTA")` should return `0.9444444444444445`.
```js
assert.equal(jaro('MARTHA', 'MARHTA'), 0.9444444444444445);
```
`jaro("DIXON", "DICKSONX")` should return `0.7666666666666666`.
```js
assert.equal(jaro('DIXON', 'DICKSONX'), 0.7666666666666666);
```
`jaro("JELLYFISH", "SMELLYFISH")` should return `0.8962962962962964`.
```js
assert.equal(jaro('JELLYFISH', 'SMELLYFISH'), 0.8962962962962964);
```
`jaro("HELLOS", "CHELLO")` should return `0.888888888888889`.
```js
assert.equal(jaro('HELLOS', 'CHELLO'), 0.888888888888889);
```
`jaro("ABCD", "BCDA")` should return `0.8333333333333334`.
```js
assert.equal(jaro('ABCD', 'BCDA'), 0.8333333333333334);
```
# --seed--
## --seed-contents--
```js
function jaro(s, t) {
@ -69,13 +97,7 @@ function jaro(s, t) {
}
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```js
function jaro(s, t) {
@ -120,7 +142,4 @@ function jaro(s, t) {
(matches / t_len) +
((matches - transpositions / 2.0) / matches)) / 3.0;
}
```
</section>