Jaro similarity: Difference between revisions
m
→{{header|Raku}}: a little more idiomatic, two more tests
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: add strict & warnings, sundry simplifications, 2 more tests) |
SqrtNegInf (talk | contribs) m (→{{header|Raku}}: a little more idiomatic, two more tests) |
||
Line 2,429:
{{trans|Perl}}
<lang perl6>sub jaro ($s, $t) {
return 1 if $s eq $t;
my $s_len = + my @s = $s.comb;
my $t_len = + my @t = $t.comb;
my $match_distance = ($s_len max $t_len) div 2 - 1;
my ($matches, @s_matches, @t_matches);
my $matches = 0;▼
for ^@s -> $i {
my $start = 0 max $i - $match_distance;
my $end = $i + $match_distance min ($t_len - 1);
for $start .. $end -> $j {
next if @t_matches[$j]
(@
}
}
for ^@s -> $i {
next unless @s_matches[$i]
$k++ until @t_matches[$k]
$transpositions++ if @s[$i]
}
( $matches
}
say jaro(.key, .value).fmt: '%.3f' for
'MARTHA' => 'MARHTA', 'DIXON' => 'DICKSONX', 'JELLYFISH' => 'SMELLYFISH',
'I repeat myself' => 'I repeat myself', '' => '';</lang>
{{out}}
<pre>0.944
0.
0.
1.000
1.000</pre>
=={{header|REXX}}==
|