hammingWeight
const hammingWeight = n => {
let count
for (count = 0; n; count++) {
n &= n - 1;
}
return count
}
const test = hammingWeight(11) // -> 3
This Gist was automatically created by Carbide, a free online programming environment.