fit in hex digest
This commit is contained in:
parent
f1d329cc0e
commit
53fcf41b3f
|
@ -16,7 +16,7 @@ module.exports = (hash, hashLength) => {
|
|||
if (hashLength < 1) return "";
|
||||
const slice = hash.slice(0, hashLength);
|
||||
if (slice.match(/[^\d]/)) return slice;
|
||||
return `${String.fromCharCode(A_CODE + parseInt(hash[0], 10))}${slice.slice(
|
||||
1
|
||||
)}`;
|
||||
return `${String.fromCharCode(
|
||||
A_CODE + (parseInt(hash[0], 10) % 6)
|
||||
)}${slice.slice(1)}`;
|
||||
};
|
||||
|
|
|
@ -23,5 +23,9 @@ it("0111", () => {
|
|||
});
|
||||
|
||||
it("911a", () => {
|
||||
expect(nonNumericOnlyHash("911a", 3)).toBe("j11");
|
||||
expect(nonNumericOnlyHash("911a", 3)).toBe("d11");
|
||||
});
|
||||
|
||||
it("511a", () => {
|
||||
expect(nonNumericOnlyHash("511a", 3)).toBe("f11");
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue