diff --git a/snippets/sdbm_hash.md b/snippets/sdbm_hash.md new file mode 100644 index 000000000..e588ee5ad --- /dev/null +++ b/snippets/sdbm_hash.md @@ -0,0 +1,13 @@ + +This function implements the **sdbm** hash-algorithm. +It uses the charCodeAt-methode and the shift-operator. + +``` js +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; +} +``` \ No newline at end of file