Skip to content

Instantly share code, notes, and snippets.

@getmetorajesh
Created August 23, 2019 07:22
Show Gist options
  • Save getmetorajesh/de61cce5f959ee58187492cd5251e92e to your computer and use it in GitHub Desktop.
Save getmetorajesh/de61cce5f959ee58187492cd5251e92e to your computer and use it in GitHub Desktop.
Hamming distance
/*
* 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