Skip to content

Instantly share code, notes, and snippets.

View rubenreyes2000's full-sized avatar

Ruben Reyes rubenreyes2000

View GitHub Profile
@rubenreyes2000
rubenreyes2000 / hash.js
Created February 2, 2024 02:02
Simple Hash function in JavaScript
/**
* A simple hashing function based on FNV-1a (Fowler-Noll-Vo) algorithm
* @param str the string to hash
* @returns the hash of the string
* @see https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
* Outputs a 128-bit hash (32 characters long)
*/
const hash = (str) => {
const FNV_PRIME = 0x01000193;
const h = [0x811c9dc5, 0x056892cd, 0x6b6b2d4f, 0x458e7388];