Skip to content

Instantly share code, notes, and snippets.

@jweinsteincbt
Created May 10, 2016 16:48
Show Gist options
  • Save jweinsteincbt/c37e0c58c72cde71615feeee2178230b to your computer and use it in GitHub Desktop.
Save jweinsteincbt/c37e0c58c72cde71615feeee2178230b to your computer and use it in GitHub Desktop.
Java hashCode in JavaScript
function hashCode(str) {
for(var i=0, total=0, len=str.length; i < len; ++i) {
total += str.charCodeAt(i)*Math.pow(31,(len - i - 1));
};
return total;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment