-
-
Notifications
You must be signed in to change notification settings - Fork 761
/
test.js
36 lines (28 loc) · 1 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const anyBase = require("any-base");
const alphabet =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_";
// an array storing the maximum string length of hashes at various bases
// 0 and 1 do not exist as possible hash lengths
const maxHashLength = [NaN, NaN];
for (let i = 2; i < 65; i++) {
const maxHash = anyBase(
anyBase.BIN,
alphabet.slice(0, i),
)(new Array(64 + 1).join("1"));
maxHashLength.push(maxHash.length);
}
console.log(maxHashLength);
// [
// NaN, NaN, 64, 41, 32, 28, 25, 23, 22, 21, 20, 19,
// 18, 18, 17, 17, 16, 16, 16, 16, 15, 15, 15, 15,
// 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13,
// 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12,
// 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11,
// 11, 11, 11, 11, 11
// ]
// refactor the above to not use any-base and still have the same result
const maxHashLength2 = [];
for (let i = 2; i < 65; i++) {
maxHashLength2.push(Math.ceil(Math.log(i) / Math.log(2)));
}
console.log(maxHashLength2);