nire0510
3/29/2016 - 1:11 PM

Generates has based on method parameters

Generates has based on method parameters

function generateHash() {
  let intHash = 0,
    strChar,
    intLength,
    strInput = [...arguments].join('');

  if (strInput.length === 0) {
    return intHash;
  }

  for (let i = 0, intLength = strInput.length; i < intLength; i++) {
    strChar   = strInput.charCodeAt(i);
    intHash  = ((intHash << 5) - intHash) + strChar;
    intHash |= 0; // Convert to 32bit integer
  }
  return intHash;
}

// Sample:
generateHash(1, 'bla', 'foo', 920);
// => 383408311
generateHash(19817623);
// => 196639745