1
Student
100%
Completion rate
The Hamming weight is the number of 1's of the binary representation of a given number.
solution.js
Write and export as default a function calculating the Hamming weight.
Examples
hammingWeight(0); // 0
hammingWeight(4); // 1
hammingWeight(101); // 4
Tips
- toString() method will help convert a number into binary
For full access to the challenge you need a professional subscription.
A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.