Javascript String getHashCode(caseSensitive)

Description

Javascript String getHashCode(caseSensitive)


String.prototype.getHashCode = function (caseSensitive) {
    var str = this;
    if (!caseSensitive) {
        str = str.toLowerCase();/*from  w ww.j  av a  2s  .c  o m*/
    }
    var hash = 1315423911, i, ch;
    for (i = str.length - 1; i >= 0; i--) {
        ch = str.charCodeAt(i);
        hash ^= ((hash << 5) + ch + (hash >> 2));
    }

    return (hash & 0x7FFFFFFF);
}



PreviousNext

Related