Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const hash = (str) => {
- let val = 0;
- const strlen = str.length;
- if (strlen === 0) { return val; }
- for (let i = 0; i < strlen; ++i) {
- const code = str.charCodeAt(i);
- val = ((val << 5) - val) + code;
- val &= val; // Int32
- }
- return (val >>> 0); // uInt32
- };
- // usage
- const myHash = hash("Hello, world"); // 3818678700
Add Comment
Please, Sign In to add comment