push
github
168 of 375 branches covered (44.8%)
Branch coverage included in aggregate %.
575 of 932 relevant lines covered (61.7%)
16.57 hits per line
1 |
export function getLeadingZeroBits(hash: Buffer) {
|
2✔ |
2 |
let total: number, i: number, bits: number |
|
3 |
|
|
4 |
for (i = 0, total = 0; i < hash.length; i++) { |
21✔ |
5 |
bits = msb(hash[i]) |
35✔ |
6 |
total += bits |
35✔ |
7 |
if (bits != 8) { |
|
8 |
break
|
20✔ |
9 |
} |
|
10 |
} |
|
11 |
return total
|
21✔ |
12 |
} |
|
13 |
|
|
14 |
function msb(b: number) { |
|
15 |
let n = 0
|
35✔ |
16 |
|
|
17 |
if (b == 0) { |
|
18 |
return 8 |
15✔ |
19 |
} |
|
20 |
|
|
21 |
// eslint-disable-next-line no-cond-assign
|
|
22 |
while (b >>= 1) { |
20✔ |
23 |
n++ |
76✔ |
24 |
} |
|
25 |
|
|
26 |
return 7 - n |
20✔ |
27 |
} |