This commit is contained in:
Gourav Goel 2024-04-25 08:24:26 +08:00 committed by GitHub
commit f3d774dfe3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,19 @@
// different power of 2 requiered so that the sum of different power of 2 equals to no..
export default function diffPowerOfTwo(number) {
if (number < 1) {
return 0;
}
var a=0;
let dividedNumber = number;
while (dividedNumber !== 1) {
if (dividedNumber % 2 !== 0) {
a+=1;
}
a+=1;
dividedNumber /= 2;
}
return a;
}