Skip to content

Instantly share code, notes, and snippets.

@gvinter
Created July 13, 2011 14:25
Show Gist options
  • Save gvinter/1080387 to your computer and use it in GitHub Desktop.
Save gvinter/1080387 to your computer and use it in GitHub Desktop.
Simple Hash
function simple_hash(key,table_size) {
var hash = 0;
for (var i = 0; i < key.length; i++) {
hash = (hash * 31) + key.charCodeAt(i);
}
return Math.abs(hash) % table_size;
}
console.log(simple_hash("Galen",100));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment