8 lines
269 B
TypeScript
8 lines
269 B
TypeScript
export const hash = (text: string): number => {
|
|
// Return number between 0 and 1.
|
|
if (!text) {
|
|
return 0;
|
|
}
|
|
const hash = Array.prototype.reduce.call(text, (hash, char) => (hash << 5) - hash + char.charCodeAt(0), 7);
|
|
return hash / (Math.pow(2, 32) - 1);
|
|
};
|