UNPKG

mathball

Version:

A JavaScript library for Competitive Programming

19 lines (15 loc) 305 B
'use strict'; /* Function: popcount() */ var validate = require('../validation/positive-integer'); function popcount(num) { var count = 0; while (num) { num &= num - 1; count++; } return count; } module.exports = function (num) { validate(num, 'popcount'); return popcount(num); };