mirror of
https://github.com/ruilisi/fortune-sheet.git
synced 2025-01-09 04:07:33 +08:00
13 lines
283 B
TypeScript
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;
|
|
}
|