Skip to content

Home

Hamming distance

Calculates the Hamming distance between two values.

const hammingDistance = (num1, num2) =>
  ((num1 ^ num2).toString(2).match(/1/g) || '').length;

hammingDistance(2, 3); // 1

More like this

Start typing a keyphrase to see matching snippets.