GithubHelp home page GithubHelp logo

php-education's People

Watchers

James Cloos avatar Raynald Mompoint avatar

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.