Implement hamming distance in JavaScript