Javascript: Hamming weight

JS: Arrays
Last update: 07 Jun 23:20
0
Students

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.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests