fortune-sheet/stories/utils.ts
2022-05-10 22:39:53 +08:00

13 lines
283 B
TypeScript

export function hashCode(str: string) {
let hash = 0;
let i;
let chr;
if (str.length === 0) return hash;
for (i = 0; i < str.length; i += 1) {
chr = str.charCodeAt(i);
hash = (hash << 5) - hash + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
}