fit in hex digest

This commit is contained in:
Ivan Kopeykin 2022-02-02 19:04:31 +03:00
parent f1d329cc0e
commit 53fcf41b3f
2 changed files with 8 additions and 4 deletions

View File

@ -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)}`;
};

View File

@ -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");
});