Nodejs生成字符串的哈希值(Hash)


Nodejs/Javascript将字符串转换成整型哈希值(Hash),然后就可以使用这些哈希值来做一些处理了。

代码

String.prototype.hashCode = function() {
  var hash = 0, i, chr;
  if (this.length === 0) return hash;
  for (i = 0; i< this.length; i++) {
    chr   = this.charCodeAt(i);
    hash  = ((hash << 5) - hash) + chr;
    hash |= 0; // Convert to 32bit integer
  }
  return hash;
};

使用

"hashstring".hashCode()

 

 

 

 

文章来源于互联网:Javascript生成字符串的哈希值(Hash)

golang后端技术

组件分享之后端组件——Golang算法练习的仓库algorithm-pattern

2022-6-19 5:51:11

后端技术服务器开发

pfx 证书导出公钥和私钥

2022-6-21 8:23:48

搜索