Skip to content

Instantly share code, notes, and snippets.

@jshcrowthe
Last active July 14, 2016 20:59
Show Gist options
  • Save jshcrowthe/98db131d679e1949dd3160cc7fc5ba6d to your computer and use it in GitHub Desktop.
Save jshcrowthe/98db131d679e1949dd3160cc7fc5ba6d to your computer and use it in GitHub Desktop.
String.prototype.hashCode
String.prototype.hashCode = function() {
var hash = 0;
if (this.length == 0) return hash;
for (i = 0; i < this.length; i++) {
char = this.charCodeAt(i);
hash = ((hash<<5)-hash)+char;
hash = hash & hash; // Convert to 32bit integer
}
return hash;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment