Files
30-seconds-of-code/snippets/sdbm-hash.md
Christian Bender 369ecbcd56 added sdbm hash algorithm
I added the sdbm hash algorithm as a function.
2017-12-24 23:30:22 +01:00

328 B

This function implements the sdbm hash-algorithm. It uses the charCodeAt-methode and the shift-operator.

function sdbm(s) {
    var hashCode = new Number();
    for (var i = 0; i < s.length; i++) {
        hashCode = s.charCodeAt(i) + (hashCode << 6) + (hashCode << 16) - hashCode;
    }
    return hashCode;
}