Hamming Distance in JavaScript
function hamming(a, b) {
const leng = a.length
let dist = 0
// strings need to be same length
if (leng != b.length) return -1;
a = a.toLowerCase()
b = b.toLowerCase()
for (let i = 0; i < leng; i++)
if (a[i] !== b[i]) dist++
return dist
}
console.log(hamming('zevan', 'kevin'))
console.log(hamming('joe', 'joe'))
console.log(hamming('john', 'jake'))
The hamming distance between two strings…