Hamming distance in JavaScript