11 lines
251 B
TypeScript
11 lines
251 B
TypeScript
|
|
export function simpleHash(str: string, seed = 0) {
|
|
let hash = seed;
|
|
for (let i = 0; i < str.length; i++) {
|
|
const char = str.charCodeAt(i);
|
|
hash = (hash << 5) - hash + char;
|
|
hash |= 0; // Convert to 32bit integer
|
|
}
|
|
return hash;
|
|
}
|