Advertisement
NonplayerCharacter

JS | Hash

Feb 20th, 2020
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // https://stackoverflow.com/a/7616484
  2. String.prototype.hashCode = function() {
  3.   var hash = 0, i, chr;
  4.   if (this.length === 0) return hash;
  5.   for (i = 0; i < this.length; i++) {
  6.     chr   = this.charCodeAt(i);
  7.     hash  = ((hash << 5) - hash) + chr;
  8.     hash |= 0; // Convert to 32bit integer
  9.   }
  10.   return hash;
  11. };
  12.  
  13. "khbdfv bkhdb fvhbdhb fvdf".hashCode()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement