Calculate string hash code - Node.js String

Node.js examples for String:String Value

Description

Calculate string hash code

Demo Code

String.prototype.hashCode = function() {
  for(var ret = 0, i = 0, len = this.length; i < len; i++) {
    ret = (31 * ret + this.charCodeAt(i)) << 0;
  }/*from w w w .ja va2 s .  c  om*/
  return ret;
};

Related Tutorials