I need the following function and it needs to be performant. I really don't know how to go about this.
function(value: string): number { ... }
The returned number needs to be between 0 and 15 and always return the same number for given strings. Duplicates are obviously allowed!
I did something similar on Node a while back but I think this would not be performant enough for my use case:
function(value: string): number {
const hash = crypto.createHash("sha256");
const hexValue: string = hash.update(value).digest("hex");
const shortenedHexValue = hexValue.substring(0, 2);
const decimalValue = parseInt(shortenedHexValue, 16);
return decimalValue / 2.55;
}
This function returned values > 0 to ~100 for given strings.