php-education's People
php-education's Issues
Jaro-Winkler bug, A compared to B does not equal B compared to A (it should)
There is a bug in your Jaro-Winkler method. A compared to B will yield a different result to B compared to A, when either A or B is a string where a character found in both strings is found more than once in one string.
To rectify this, when identifying common characters, the same character should not be repeated. The common characters variable needs to be deduplicated before returned.
The below code replaces the common characters string with an array that uses the common character as the key, to avoid duplication. By using the code below, A compared to B yields the same results as B compared to A.
This is in line with the C# version of the method.
//$commonCharacters='';
$commonCharacters = [];
for( $i=0; $i < $str1_len; $i++){
$noMatch = True;
// compare if char does match inside given allowedDistance
// and if it does add it to commonCharacters
for( $j= max( 0, $i-$allowedDistance ); $noMatch && $j < min( $i + $allowedDistance + 1, $str2_len ); $j++) {
if( $temp_string2[(int)$j] == $string1[$i] ){ // MJR
$noMatch = False;
//$commonCharacters .= $string1[$i];
$commonCharacters[$string1[$i]] = $string1[$i];
$temp_string2[(int)$j] = ''; // MJR
}
}
}
//return $commonCharacters;
return implode("", $commonCharacters);
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.