Created
August 23, 2019 07:22
-
-
Save getmetorajesh/de61cce5f959ee58187492cd5251e92e to your computer and use it in GitHub Desktop.
Hamming distance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Hamming distance refers to the number of points at which two variables differ, | |
* calculated by simply adding up the number of spots where two variables differ. | |
* The variable can be binary or strings. | |
* Used for finding genetic distance or to find the no of distorted bits to estimate error | |
*/ | |
const hammingDistance = (x, y) => { | |
let inc = 0 | |
let count = 0 | |
while (x[inc]) { | |
if (x[inc] !== y[inc]) { | |
count++ | |
} | |
inc++ | |
} | |
return count | |
} | |
const res = hammingDistance('karhlin', 'kathlin') | |
// Runtime is |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment