Skip to content

Instantly share code, notes, and snippets.

@earlin
Last active May 30, 2019 00:08
Show Gist options
  • Save earlin/59893fe95716fdead48d196faeddb8ab to your computer and use it in GitHub Desktop.
Save earlin/59893fe95716fdead48d196faeddb8ab to your computer and use it in GitHub Desktop.
export default function hash(string) {
const length = string.length;
let h = 0, a = 63689, b = 378551;
for (let i = 0; i < length; i++)
{
h = (Math.imul(h, a) + string.charCodeAt(i)) >>> 0;
a = Math.imul(a, b) >>> 0;
}
return h;
}

the original link has the equivalent of the following:

import hash from "./RSHash.js";
const data = "jdfgsdhfsdfsd 6445dsfsd7fg/*/+bfjsdgf%$^";
const value = RSHash(data);

and I checked it on my node env it returns:

2012450421

I know this is not enough, but this is fine for me.

@earlin
Copy link
Author

earlin commented May 30, 2019

Licence: Public Domain,
Attribute is not needed but appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment