Created
March 12, 2015 12:48
-
-
Save bitboxx/6d6cd6ab20ce55ac0e01 to your computer and use it in GitHub Desktop.
Quick string hashing Javascript function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a modified version of similar functions found here: | |
// http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery | |
// http://jsperf.com/hashing-strings | |
String.prototype.hash = function () { | |
var res = 0, | |
len = this.length; | |
for (i = 0; i < len; i++) { | |
res = res * 31 + this.charCodeAt(i); | |
res = res & res; | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment