Nodejs String Hash hashCode()

Here you can find the source of hashCode()

Method Source Code

/**//from w w  w  . j  a  va 2 s .c  o m
 * @license
 * Copyright 2012 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
String.prototype.hashCode = function() {
  var hash = 0;
  if ( this.length == 0 ) return hash;

  for (i = 0; i < this.length; i++) {
    var code = this.charCodeAt(i);
    hash = ((hash << 5) - hash) + code;
    hash &= hash;
  }

  return hash;
};

Related

  1. hashCode()
    String.prototype.hashCode = function() {
      var hash = 0, i, chr, len;
      if (this.length === 0) return hash;
      for (i = 0, len = this.length; i < len; i++) {
        chr   = this.charCodeAt(i);
        hash  = ((hash << 5) - hash) + chr;
        hash |= 0; 
      return hash;
    ...
    
  2. hashCode()
    String.prototype.hashCode = function() {
      var hash = 0, i, chr, len;
      if (this.length == 0) return hash;
      for (i = 0, len = this.length; i < len; i++) {
        chr   = this.charCodeAt(i);
        hash  = ((hash << 5) - hash) + chr;
        hash |= 0; 
      return hash;
    ...
    
  3. hashCode()
    String.prototype.hashCode = function(){
        var hash = 0;
        if (this.length == 0) return hash;
        for (var i = 0; i < this.length; i++) {
            var character = this.charCodeAt(i);
            hash = ((hash<<5)-hash)+character;
            hash = hash & hash; 
        return hash;
    ...
    
  4. hashCode()
    function roundNumber(number, decimals) {
        var newnumber = new Number(number+'').toFixed(parseInt(decimals));
        return parseFloat(newnumber);
    };
    String.prototype.hashCode = function(){
        var hash = 0, i, char;
        if (this.length == 0) return hash;
        for (i = 0; i < this.length; i++) {
            char = this.charCodeAt(i);
    ...
    
  5. hashCode()
    String.prototype.hashCode = function() {
      var hash = 0, i, chr, len;
      if (this.length == 0) return hash;
      for (i = 0, len = this.length; i < len; i++) {
        chr   = this.charCodeAt(i);
        hash  = ((hash << 5) - hash) + chr;
        hash |= 0; 
      return hash;
    ...
    
  6. hashCode()
    String.prototype.hashCode = function(){
        var hash = 0;
        if (this.length === 0) return hash;
        for (i = 0; i < this.length; i++) {
            char = this.charCodeAt(i);
            hash = ((hash<<5)-hash)+char;
            hash = hash & hash; 
        return hash;
    ...
    
  7. hashCode()
    String.prototype.hashCode = function(){
        var hash = 0;
        if (this.length == 0) return hash
        for (i = 0; i < this.length; i++) {
            char = this.charCodeAt(i)
            hash = ((hash << 5) - hash) + char
            hash |= 0 
        return hash
    ...
    
  8. hashCode()
    String.prototype.hashCode = function () {
        var hash = 0, i, chr, len;
        if (this.length === 0)
            return hash;
        for (i = 0, len = this.length; i < len; i++) {
            chr = this.charCodeAt(i);
            hash = ((hash << 5) - hash) + chr;
            hash |= 0; 
        return hash;
    };
    
  9. hashCode()
    String.prototype.hashCode = function(){
        var hash = 0;
        if (this.length == 0) return hash;
        for (i = 0; i < this.length; i++) {
            char = this.charCodeAt(i);
            hash = ((hash<<5)-hash)+char;
            hash = hash & hash; 
        return hash;
    ...