(a)
| 8 | */ |
| 9 | |
| 10 | function BinaryCountSetBits(a) { |
| 11 | 'use strict' |
| 12 | |
| 13 | // check whether input is an integer, some non-integer number like, 21.1 have non-terminating binary expansions and hence their binary expansion will contain infinite ones, thus the handling of non-integers (including strings,objects etc. as it is meaningless) has been omitted |
| 14 | |
| 15 | if (!Number.isInteger(a)) throw new TypeError('Argument not an Integer') |
| 16 | |
| 17 | let count = 0 |
| 18 | while (a) { |
| 19 | a &= a - 1 |
| 20 | count++ |
| 21 | } |
| 22 | |
| 23 | return count |
| 24 | } |
| 25 | |
| 26 | export { BinaryCountSetBits } |
no outgoing calls
no test coverage detected