peterschussheim
7/25/2017 - 9:28 PM

hammingWeight

hammingWeight

const hammingWeight = n => {
  let count
  for (count = 0; n; count++) {
      n &= n - 1;
  }
    return count
}

const test = hammingWeight(11) // -> 3

hammingWeight

This Gist was automatically created by Carbide, a free online programming environment.

You can view a live, interactive version of this Gist here.